Skip to content

Commit

Permalink
Draw tool improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Oct 23, 2024
1 parent d229694 commit b188c7d
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 119 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions creator/src/modelfxeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ impl ModelFXEditor {

// Brush Size

let mut text = TheText::new(TheId::empty());
text.set_text("Brush Size".to_string());
toolbar_hlayout.add_widget(Box::new(text));
// let mut text = TheText::new(TheId::empty());
// text.set_text("Brush Size".to_string());
// toolbar_hlayout.add_widget(Box::new(text));

let mut brush_size = TheSlider::new(TheId::named("Brush Size"));
let mut brush_size = TheTextLineEdit::new(TheId::named("Brush Size"));
brush_size.set_value(TheValue::Float(self.brush_size));
brush_size.set_default_value(TheValue::Float(1.0));
//brush_size.set_default_value(TheValue::Float(1.0));
brush_size.set_info_text(Some("Brush Size".to_string()));
brush_size.set_range(TheValue::RangeF32(0.01..=5.0));
brush_size.set_continuous(true);
brush_size.limiter_mut().set_max_width(170);
Expand All @@ -156,13 +157,14 @@ impl ModelFXEditor {

// Falloff

let mut text = TheText::new(TheId::empty());
text.set_text("Falloff".to_string());
toolbar_hlayout.add_widget(Box::new(text));
// let mut text = TheText::new(TheId::empty());
// text.set_text("Falloff".to_string());
// toolbar_hlayout.add_widget(Box::new(text));

let mut falloff = TheSlider::new(TheId::named("Falloff"));
let mut falloff = TheTextLineEdit::new(TheId::named("Falloff"));
falloff.set_value(TheValue::Float(self.falloff));
falloff.set_default_value(TheValue::Float(0.0));
//falloff.set_default_value(TheValue::Float(0.0));
falloff.set_info_text(Some("Falloff".to_string()));
falloff.set_range(TheValue::RangeF32(0.0..=1.0));
falloff.set_continuous(true);
falloff.limiter_mut().set_max_width(170);
Expand Down
6 changes: 3 additions & 3 deletions creator/src/tileeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl TileEditor {
Self {
curr_tile_uuid: None,

curr_layer_role: Layer2DRole::Wall,
curr_layer_role: Layer2DRole::Ground,

icon_normal_border_color: [100, 100, 100, 255],
icon_selected_border_color: [255, 255, 255, 255],
Expand Down Expand Up @@ -89,14 +89,14 @@ impl TileEditor {
ground_icon.set_text_size(10.0);
ground_icon.set_text_color([200, 200, 200, 255]);
ground_icon.limiter_mut().set_max_size(vec2i(48, 48));
ground_icon.set_border_color(Some(self.icon_normal_border_color));
ground_icon.set_border_color(Some(self.icon_selected_border_color));

let mut wall_icon = TheIconView::new(TheId::named("Wall Icon"));
wall_icon.set_text(Some("WALL".to_string()));
wall_icon.set_text_size(10.0);
wall_icon.set_text_color([200, 200, 200, 255]);
wall_icon.limiter_mut().set_max_size(vec2i(48, 48));
wall_icon.set_border_color(Some(self.icon_selected_border_color));
wall_icon.set_border_color(Some(self.icon_normal_border_color));

let mut ceiling_icon = TheIconView::new(TheId::named("Ceiling Icon"));
ceiling_icon.set_text(Some("CEILING".to_string()));
Expand Down
234 changes: 149 additions & 85 deletions creator/src/tools/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ use crate::{prelude::*, DEFAULT_VLAYOUT_RATIO};
use rayon::prelude::*;
use ToolEvent::*;

use crate::editor::{BRUSHLIST, MODELFXEDITOR, PANELS, PRERENDERTHREAD, TILEDRAWER, UNDOMANAGER};
use crate::editor::{
BRUSHLIST, MODELFXEDITOR, PANELS, PRERENDERTHREAD, SIDEBARMODE, TILEDRAWER, UNDOMANAGER,
};

pub struct DrawTool {
id: TheId,

processed_coords: FxHashSet<Vec2i>,
roughness: f32,
metallic: f32,
bump: f32,
opacity: f32,
}

Expand All @@ -20,6 +25,9 @@ impl Tool for DrawTool {
id: TheId::named("Draw Tool"),
processed_coords: FxHashSet::default(),

roughness: 0.5,
metallic: 0.0,
bump: 0.0,
opacity: 1.0,
}
}
Expand Down Expand Up @@ -60,41 +68,60 @@ impl Tool for DrawTool {
if let Some(layout) = ui.get_hlayout("Game Tool Params") {
layout.clear();

let mut roughness = TheTextLineEdit::new(TheId::named("Roughness"));
roughness.set_value(TheValue::Float(self.roughness));
// opacity.set_default_value(TheValue::Float(1.0));
roughness.set_info_text(Some("Roughness".to_string()));
roughness.set_range(TheValue::RangeF32(0.0..=1.0));
roughness.set_continuous(true);
roughness.limiter_mut().set_max_width(150);
roughness
.set_status_text("The roughness of the brush. Only for palette colors.");
layout.add_widget(Box::new(roughness));

let mut metallic = TheTextLineEdit::new(TheId::named("Metallic"));
metallic.set_value(TheValue::Float(self.metallic));
// opacity.set_default_value(TheValue::Float(1.0));
metallic.set_info_text(Some("Metallic".to_string()));
metallic.set_range(TheValue::RangeF32(0.0..=1.0));
metallic.set_continuous(true);
metallic.limiter_mut().set_max_width(150);
metallic.set_status_text(
"The metallic property of the brush. Only for palette colors.",
);
layout.add_widget(Box::new(metallic));

let mut bump = TheTextLineEdit::new(TheId::named("Bump"));
bump.set_value(TheValue::Float(self.bump));
// opacity.set_default_value(TheValue::Float(1.0));
bump.set_info_text(Some("Bump".to_string()));
bump.set_range(TheValue::RangeF32(0.0..=1.0));
bump.set_continuous(true);
bump.limiter_mut().set_max_width(150);
bump.set_status_text("The bump value of the brush. Only for palette colors and only used if greater than 0.0.");
layout.add_widget(Box::new(bump));

// Opacity
let mut text = TheText::new(TheId::empty());
text.set_text("Opacity".to_string());
layout.add_widget(Box::new(text));
// let mut text = TheText::new(TheId::empty());
// text.set_text("Opacity".to_string());
// layout.add_widget(Box::new(text));

let mut opacity = TheSlider::new(TheId::named("Opacity"));
let mut opacity = TheTextLineEdit::new(TheId::named("Opacity"));
opacity.set_value(TheValue::Float(self.opacity));
opacity.set_default_value(TheValue::Float(1.0));
//opacity.set_default_value(TheValue::Float(1.0));
opacity.set_info_text(Some("Opacity".to_string()));
opacity.set_range(TheValue::RangeF32(0.0..=1.0));
opacity.set_continuous(true);
opacity.limiter_mut().set_max_width(170);
opacity.set_status_text("The opacity off the brush.");
layout.add_widget(Box::new(opacity));

//
let mut spacer = TheIconView::new(TheId::empty());
spacer.limiter_mut().set_max_width(5);
layout.add_widget(Box::new(spacer));

// Align Group
/*
let mut gb = TheGroupButton::new(TheId::named("Draw Align Group"));
gb.add_text_status(
str!("Tile Align"),
str!("Draw aligned to the tiles of the regions."),
);
gb.add_text_status(str!("Freeform"), str!("Draw without any restrictions."));
gb.set_item_width(75);
gb.set_index(self.align_index);
layout.add_widget(Box::new(gb));
// let mut spacer = TheIconView::new(TheId::empty());
// spacer.limiter_mut().set_max_width(5);
// layout.add_widget(Box::new(spacer));

layout.set_reverse_index(Some(1));
*/
}

if let Some(layout) = ui.get_sharedvlayout("Shared VLayout") {
Expand Down Expand Up @@ -134,6 +161,8 @@ impl Tool for DrawTool {
.cloned();

let palette = project.palette.clone();
let palette_color = project.palette.get_current_color();

if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
let mut region_to_render: Option<Region> = None;
let mut tiles_to_render: Vec<Vec2i> = vec![];
Expand Down Expand Up @@ -162,6 +191,8 @@ impl Tool for DrawTool {
TheRGBBuffer::new(TheDim::sized(region.grid_size, region.grid_size))
};

let mode = SIDEBARMODE.lock().unwrap();

// -- Paint the material into the tile

let mat_obj_params = material_obj.load_parameters(&TheTime::default());
Expand Down Expand Up @@ -215,66 +246,87 @@ impl Tool for DrawTool {
let tile_y_f = coord.y as f32 + uv.y;

if d < 0.0 {
let mut hit = Hit {
two_d: true,
..Default::default()
};

hit.normal = vec3f(0.0, 1.0, 0.0);
hit.hit_point = vec3f(uv.x, 0.0, uv.y);

hit.uv = uv;
hit.global_uv = vec2f(tile_x_f, tile_y_f);
hit.pattern_pos = hit.global_uv;

material_obj.compute(
&mut hit,
&palette,
&tiles.tiles,
&mat_obj_params,
);

let col = TheColor::from_vec3f(hit.mat.base_color)
.to_u8_array();

let c = mix_color(pixel1, &col, opacity);

pixel1[0] = c[0];
pixel1[1] = c[1];
pixel1[2] = c[2];

let roughness = lerp(
pixel2[0] as f32 / 255.0,
hit.mat.roughness,
opacity,
);

let metallic = lerp(
pixel2[1] as f32 / 255.0,
hit.mat.metallic,
opacity,
);

pixel2[0] = (roughness * 255.0) as u8;
pixel2[1] = (metallic * 255.0) as u8;

hit.mode = HitMode::Bump;
material_obj.follow_trail(
0,
0,
&mut hit,
&palette,
&tiles.tiles,
&mat_obj_params,
);

let bump = lerp(
pixel2[2] as f32 / 255.0,
hit.bump,
opacity,
);

pixel2[2] = (bump * 255.0) as u8;
if *mode == SidebarMode::Material {
let mut hit = Hit {
two_d: true,
..Default::default()
};

hit.normal = vec3f(0.0, 1.0, 0.0);
hit.hit_point = vec3f(uv.x, 0.0, uv.y);

hit.uv = uv;
hit.global_uv = vec2f(tile_x_f, tile_y_f);
hit.pattern_pos = hit.global_uv;

material_obj.compute(
&mut hit,
&palette,
&tiles.tiles,
&mat_obj_params,
);

let col =
TheColor::from_vec3f(hit.mat.base_color)
.to_u8_array();

let c = mix_color(pixel1, &col, opacity);

pixel1[0] = c[0];
pixel1[1] = c[1];
pixel1[2] = c[2];

let roughness = lerp(
pixel2[0] as f32 / 255.0,
hit.mat.roughness,
opacity,
);

let metallic = lerp(
pixel2[1] as f32 / 255.0,
hit.mat.metallic,
opacity,
);

pixel2[0] = (roughness * 255.0) as u8;
pixel2[1] = (metallic * 255.0) as u8;

hit.mode = HitMode::Bump;
material_obj.follow_trail(
0,
0,
&mut hit,
&palette,
&tiles.tiles,
&mat_obj_params,
);

let bump = lerp(
pixel2[2] as f32 / 255.0,
hit.bump,
opacity,
);

pixel2[2] = (bump * 255.0) as u8;
} else {
let mut color = BLACK;

if let Some(palette_color) = &palette_color {
color = palette_color.to_u8_array();
}

pixel1[0] = color[0];
pixel1[1] = color[1];
pixel1[2] = color[2];

let bump = self.bump;
let roughness = self.roughness;
let metallic = self.metallic;

pixel2[0] = (roughness * 255.0) as u8;
pixel2[1] = (metallic * 255.0) as u8;
pixel2[2] = (bump * 255.0) as u8;
}
}
});
});
Expand Down Expand Up @@ -488,7 +540,19 @@ impl Tool for DrawTool {
#[allow(clippy::single_match)]
match &event {
TheEvent::ValueChanged(id, value) => {
if id.name == "Opacity" {
if id.name == "Roughness" {
if let Some(size) = value.to_f32() {
self.roughness = size;
}
} else if id.name == "Metallic" {
if let Some(size) = value.to_f32() {
self.metallic = size;
}
} else if id.name == "Bump" {
if let Some(size) = value.to_f32() {
self.bump = size;
}
} else if id.name == "Opacity" {
if let Some(size) = value.to_f32() {
self.opacity = size;
}
Expand Down
Loading

0 comments on commit b188c7d

Please sign in to comment.