learned the renderer material was fucking the color
This commit is contained in:
parent
50749acacb
commit
cbe54774b8
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
"./Cargo.toml",
|
"./Cargo.toml",
|
||||||
"./Cargo.toml",
|
"./Cargo.toml",
|
||||||
"./Cargo.toml",
|
"./Cargo.toml",
|
||||||
|
"./Cargo.toml",
|
||||||
"./Cargo.toml"
|
"./Cargo.toml"
|
||||||
],
|
],
|
||||||
}
|
}
|
|
@ -38,6 +38,7 @@ pub fn startup(
|
||||||
mesh_assets: ResMut<Assets<Mesh>>,
|
mesh_assets: ResMut<Assets<Mesh>>,
|
||||||
mut oct_assets: ResMut<Assets<OctTreeAsset>>,
|
mut oct_assets: ResMut<Assets<OctTreeAsset>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
let id = OctTreeAsset::load(&mut pairs, asset_server, mesh_assets, "test.vvg".into());
|
let id = OctTreeAsset::load(&mut pairs, asset_server, mesh_assets, "test.vvg".into());
|
||||||
let parent = commands
|
let parent = commands
|
||||||
|
@ -50,6 +51,8 @@ pub fn startup(
|
||||||
.spawn((
|
.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: id.clone(),
|
mesh: id.clone(),
|
||||||
|
material: materials.add(Color::rgb(1., 1., 1.)),
|
||||||
|
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
OctAssetMarker {
|
OctAssetMarker {
|
||||||
|
@ -62,8 +65,8 @@ pub fn startup(
|
||||||
|
|
||||||
commands.spawn(PointLightBundle {
|
commands.spawn(PointLightBundle {
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
intensity: 1000.0,
|
intensity: 100000.0,
|
||||||
range: 100.0,
|
range: 1000.0,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
transform: light_transform,
|
transform: light_transform,
|
||||||
|
|
|
@ -8,10 +8,13 @@ use bevy::{
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
use bevy_egui::{
|
use bevy_egui::{
|
||||||
egui::{self, color_picker, Color32},
|
egui::{
|
||||||
|
self, color_picker,
|
||||||
|
ecolor::{hsv_from_rgb, rgb_from_hsv},
|
||||||
|
epaint::Hsva,
|
||||||
|
},
|
||||||
EguiContexts, EguiPlugin,
|
EguiContexts, EguiPlugin,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
vvedit::editor_bevy_input_shim::keybind_codes::REMOVE_VOXEL,
|
vvedit::editor_bevy_input_shim::keybind_codes::REMOVE_VOXEL,
|
||||||
|
@ -30,8 +33,15 @@ use super::{
|
||||||
orbit_camera::orbit_camera::{pan_orbit_camera, spawn_camera},
|
orbit_camera::orbit_camera::{pan_orbit_camera, spawn_camera},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Default, Resource)]
|
||||||
|
pub struct EditWindowUIState {
|
||||||
|
brush_color: Hsva,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn register_edit_ui(app: &mut bevy::prelude::App) -> &mut bevy::prelude::App {
|
pub fn register_edit_ui(app: &mut bevy::prelude::App) -> &mut bevy::prelude::App {
|
||||||
app.insert_resource(EditWindowUIState {});
|
app.insert_resource(EditWindowUIState {
|
||||||
|
brush_color: egui_color_from(Color::RED),
|
||||||
|
});
|
||||||
app.add_plugins(EguiPlugin);
|
app.add_plugins(EguiPlugin);
|
||||||
app.add_systems(Startup, startup_system_edit_ui);
|
app.add_systems(Startup, startup_system_edit_ui);
|
||||||
app.add_systems(Update, edit_window_ui);
|
app.add_systems(Update, edit_window_ui);
|
||||||
|
@ -44,26 +54,21 @@ pub fn startup_system_edit_ui(commands: Commands) {
|
||||||
spawn_camera(commands);
|
spawn_camera(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Resource)]
|
|
||||||
pub struct EditWindowUIState {}
|
|
||||||
|
|
||||||
pub fn edit_click_events(
|
pub fn edit_click_events(
|
||||||
input_data: ResMut<InputRegister>,
|
input_data: ResMut<InputRegister>,
|
||||||
camera_query: Query<(&Camera, &GlobalTransform)>,
|
camera_query: Query<(&Camera, &GlobalTransform)>,
|
||||||
oct_tree: Query<(&GlobalTransform, &OctAssetMarker)>,
|
oct_tree: Query<(&GlobalTransform, &OctAssetMarker)>,
|
||||||
windows: Query<&Window>,
|
windows: Query<&Window>,
|
||||||
mut oct_assets: ResMut<Assets<OctTreeAsset>>,
|
mut oct_assets: ResMut<Assets<OctTreeAsset>>,
|
||||||
|
shared_ui_state: ResMut<EditWindowUIState>,
|
||||||
) {
|
) {
|
||||||
let paint = input_data.get_binary_input(&PAINT_VOXEL.into());
|
let paint = input_data.get_binary_input(&PAINT_VOXEL.into());
|
||||||
let remove = input_data.get_binary_input(&REMOVE_VOXEL.into());
|
let remove = input_data.get_binary_input(&REMOVE_VOXEL.into());
|
||||||
let insert = input_data.get_binary_input(&INSERT_VOXEL.into());
|
let insert = input_data.get_binary_input(&INSERT_VOXEL.into());
|
||||||
|
|
||||||
for window in &windows {
|
for window in &windows {
|
||||||
for (trans, oct) in &oct_tree {
|
for (trans, oct) in &oct_tree {
|
||||||
for (camera, cam_trans) in &camera_query {
|
for (camera, cam_trans) in &camera_query {
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
let r: f32 = rng.gen_range(0.0..1.0);
|
|
||||||
let g: f32 = rng.gen_range(0.0..1.0);
|
|
||||||
let b: f32 = rng.gen_range(0.0..1.0);
|
|
||||||
let Some(cursor_pos) = window.cursor_position() else {
|
let Some(cursor_pos) = window.cursor_position() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -82,8 +87,10 @@ pub fn edit_click_events(
|
||||||
if let Some(_) = paint.filter(|input| input.pressed()) {
|
if let Some(_) = paint.filter(|input| input.pressed()) {
|
||||||
if collision.is_some() {
|
if collision.is_some() {
|
||||||
let col = collision.unwrap();
|
let col = collision.unwrap();
|
||||||
edit_octtree
|
edit_octtree.set_voxel_at_location(
|
||||||
.set_voxel_at_location(col.voxel_index_location, Color::rgb(r, g, b));
|
col.voxel_index_location,
|
||||||
|
color_from(shared_ui_state.brush_color),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if let Some(_) = remove.filter(|input| input.pressed()) {
|
} else if let Some(_) = remove.filter(|input| input.pressed()) {
|
||||||
if collision.is_some() {
|
if collision.is_some() {
|
||||||
|
@ -97,7 +104,10 @@ pub fn edit_click_events(
|
||||||
let hitloc = col.hit_data.hitpoint.local.clone();
|
let hitloc = col.hit_data.hitpoint.local.clone();
|
||||||
let hitnorm = col.hit_data.normal.local.clone();
|
let hitnorm = col.hit_data.normal.local.clone();
|
||||||
let hitvox = hitloc + (hitnorm * 0.25);
|
let hitvox = hitloc + (hitnorm * 0.25);
|
||||||
edit_octtree.set_voxel_at_location(hitvox.round(), Color::rgb(r, g, b));
|
edit_octtree.set_voxel_at_location(
|
||||||
|
hitvox.round(),
|
||||||
|
color_from(shared_ui_state.brush_color),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,12 +116,11 @@ pub fn edit_click_events(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn edit_window_ui(
|
pub fn edit_window_ui(
|
||||||
mut _shared_ui_state: ResMut<EditWindowUIState>,
|
mut shared_ui_state: ResMut<EditWindowUIState>,
|
||||||
mut contexts: EguiContexts,
|
mut contexts: EguiContexts,
|
||||||
mut oct_assets: ResMut<Assets<OctTreeAsset>>,
|
mut oct_assets: ResMut<Assets<OctTreeAsset>>,
|
||||||
mut pairs: ResMut<MeshingOctTreePairs>,
|
mut pairs: ResMut<MeshingOctTreePairs>,
|
||||||
) {
|
) {
|
||||||
let mut color: Color32 = Default::default();
|
|
||||||
egui::Window::new("VVEdit").show(contexts.ctx_mut(), |ui| {
|
egui::Window::new("VVEdit").show(contexts.ctx_mut(), |ui| {
|
||||||
let mut label = String::from("Pre-Alpha");
|
let mut label = String::from("Pre-Alpha");
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
@ -119,8 +128,11 @@ pub fn edit_window_ui(
|
||||||
writeln!(label, "click adds a voxel:").ok();
|
writeln!(label, "click adds a voxel:").ok();
|
||||||
writeln!(label, "R+click removes a voxel:").ok();
|
writeln!(label, "R+click removes a voxel:").ok();
|
||||||
writeln!(label, "E+click paints (edits) a voxel:").ok();
|
writeln!(label, "E+click paints (edits) a voxel:").ok();
|
||||||
|
color_picker::color_picker_hsva_2d(
|
||||||
color_picker::color_picker_color32(ui, &mut color, color_picker::Alpha::Opaque);
|
ui,
|
||||||
|
&mut shared_ui_state.brush_color,
|
||||||
|
color_picker::Alpha::Opaque,
|
||||||
|
);
|
||||||
ui.label(label);
|
ui.label(label);
|
||||||
if ui.button("Add Origin Voxel").clicked() {
|
if ui.button("Add Origin Voxel").clicked() {
|
||||||
//
|
//
|
||||||
|
@ -130,9 +142,61 @@ pub fn edit_window_ui(
|
||||||
if tree.is_some() {
|
if tree.is_some() {
|
||||||
//
|
//
|
||||||
let tree = tree.unwrap();
|
let tree = tree.unwrap();
|
||||||
tree.model.set_voxel_at_location(Vec3::ZERO, Color::BLUE);
|
tree.model
|
||||||
|
.set_voxel_at_location(Vec3::ZERO, color_from(shared_ui_state.brush_color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn color_from(egui_color: Hsva) -> Color {
|
||||||
|
let rgb = rgb_from_hsv((egui_color.h, egui_color.s, egui_color.v));
|
||||||
|
return Color::rgb_linear_from_array(rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn egui_color_from(color: Color) -> Hsva {
|
||||||
|
let x = hsv_from_rgb([color.r(), color.g(), color.b()]);
|
||||||
|
|
||||||
|
return Hsva::new(x.0, x.1, x.2, 1.);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn round_trip_color() {
|
||||||
|
use rand::Rng;
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let min = 0.;
|
||||||
|
let max = 1.;
|
||||||
|
for _ in 0..10000 {
|
||||||
|
let r = rng.gen_range(min..max);
|
||||||
|
let g = rng.gen_range(min..max);
|
||||||
|
let b = rng.gen_range(min..max);
|
||||||
|
let mut color = Color::rgb(r, g, b);
|
||||||
|
let mut egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
egui_color = egui_color_from(color);
|
||||||
|
color = color_from(egui_color);
|
||||||
|
assert_eq!((color.r() * 255.).floor(), (r * 255.).floor());
|
||||||
|
assert_eq!((color.g() * 255.).floor(), (g * 255.).floor());
|
||||||
|
assert_eq!((color.b() * 255.).floor(), (b * 255.).floor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
pub fn test_colors() {
|
||||||
|
let color = Color::rgb(1., 0., 0.);
|
||||||
|
//let x = Hsva::from_srgb()
|
||||||
|
let hsv = egui_color_from(color);
|
||||||
|
let conv = rgb_from_hsv((hsv.h, hsv.s, hsv.v));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue