Skip to content

Commit

Permalink
removed the tool ENUM and fix of the hardness bug
Browse files Browse the repository at this point in the history
- enum {PAINT, BLUR, FILL, SAMPLE, DISPLACE}
- _match_tool func

 * replaced with a function call.
---------
+ hardness now works on all blend modes.
  • Loading branch information
tomankirilov committed Feb 15, 2021
1 parent 1f30d14 commit dbb9c15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
35 changes: 12 additions & 23 deletions addons/vpainter/vpainter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var blend_mode = MIX
enum {STANDART, INFLATE, MOVE, SMOOTH}
var sculpt_mode = STANDART

enum {PAINT, BLUR, FILL, SAMPLE, DISPLACE}
var current_tool = PAINT
var current_tool = "_paint_tool"


var invert_brush = false

Expand Down Expand Up @@ -60,8 +60,7 @@ func forward_spatial_gui_input(camera, event) -> bool:
if raycast_hit:
return _user_input(event) #the returned value blocks or unblocks the default input from godot
else:
return true

return false

func _user_input(event) -> bool:
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
Expand All @@ -87,26 +86,16 @@ func _user_input(event) -> bool:

func _process_drawing():
while process_drawing:
_match_tool()
call(current_tool)
yield(get_tree().create_timer(brush_spacing), "timeout")

func _match_tool() -> void:
match current_tool:
PAINT:
_paint_tool()
BLUR:
_blur_tool()
FILL:
_fill_tool()
SAMPLE:
_sample_tool()
DISPLACE:
_displace_tool()

func _display_brush() -> void:
# if raycast_hit:
if raycast_hit:
brush_cursor.visible = true
brush_cursor.translation = hit_position
brush_cursor.scale = Vector3.ONE * calculated_size
else:
brush_cursor.visible = false

func _calculate_brush_pressure(event) -> void:
if event is InputEventMouseMotion:
Expand Down Expand Up @@ -155,13 +144,13 @@ func _paint_tool() -> void:
MIX:
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(paint_color, calculated_opacity * calculated_hardness))
ADD:
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) + paint_color, calculated_opacity))
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) + paint_color, calculated_opacity * calculated_hardness))
SUBTRACT:
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) - paint_color, calculated_opacity))
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) - paint_color, calculated_opacity * calculated_hardness))
MULTIPLY:
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) * paint_color, calculated_opacity))
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) * paint_color, calculated_opacity * calculated_hardness))
DIVIDE:
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) / paint_color, calculated_opacity))
data.set_vertex_color(i, data.get_vertex_color(i).linear_interpolate(data.get_vertex_color(i) / paint_color, calculated_opacity * calculated_hardness))

current_mesh.mesh.surface_remove(0)
data.commit_to_surface(current_mesh.mesh)
Expand Down
15 changes: 5 additions & 10 deletions addons/vpainter/vpainter_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ func _set_size_pressure(value):

func _set_paint_tool(value):
if value:
print("PAINT TOOL ACTICATED")
vpainter.current_tool = vpainter.PAINT
vpainter.current_tool = "_paint_tool"
pen_pressure_settings.visible = true
blend_modes.visible = true

Expand All @@ -181,8 +180,7 @@ func _set_paint_tool(value):

func _set_sample_tool(value):
if value:
print("SAMPLE TOOL ACTICATED")
vpainter.current_tool = vpainter.SAMPLE
vpainter.current_tool = "_sample_tool"
pen_pressure_settings.visible = false
blend_modes.visible = false

Expand All @@ -194,8 +192,7 @@ func _set_sample_tool(value):

func _set_blur_tool(value):
if value:
print("BLUR TOOL ACTICATED")
vpainter.current_tool = vpainter.BLUR
vpainter.current_tool = "_blur_tool"
pen_pressure_settings.visible = false
blend_modes.visible = false

Expand All @@ -207,8 +204,7 @@ func _set_blur_tool(value):

func _set_displace_tool(value):
if value:
print("DISPLACE TOOL ACTICATED")
vpainter.current_tool = vpainter.DISPLACE
vpainter.current_tool = "_displace_tool"
pen_pressure_settings.visible = true
blend_modes.visible = false

Expand All @@ -221,8 +217,7 @@ func _set_displace_tool(value):

func _set_fill_tool(value):
if value:
print("FILL TOOL ACTICATED")
vpainter.current_tool = vpainter.FILL
vpainter.current_tool = "_fill_tool"
pen_pressure_settings.visible = false
blend_modes.visible = true

Expand Down

0 comments on commit dbb9c15

Please sign in to comment.