Implemented basic functionality for interaction with editables.

This commit is contained in:
mono 2022-01-02 03:09:18 +01:00
parent f6209c3aa9
commit 83d6a31683
8 changed files with 147 additions and 43 deletions

View File

@ -1,6 +1,21 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://production/blueprints/mannequin/mat.tres" type="Material" id=1]
[sub_resource type="Shader" id=3]
code = "shader_type spatial;
render_mode blend_mix, depth_draw_opaque, unshaded, depth_test_disable;
void fragment() {
//ALBEDO = vec3(0.8, 0.2, 0.2);
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r;
float weight = clamp((depth - FRAGCOORD.z) * 1000000000.0, 0.0, 0.5);
vec3 screen_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
ALBEDO = mix(vec3(0.8, 1.2, 0.2), screen_color, weight);
}"
[sub_resource type="ShaderMaterial" id=4]
render_priority = 1
shader = SubResource( 3 )
[sub_resource type="ArrayMesh" id=2]
surfaces/0 = {
@ -16,6 +31,9 @@ surfaces/0 = {
}
[node name="TestCapsule" type="MeshInstance" groups=["SummerDaySpatialTransform"]]
material_override = ExtResource( 1 )
material_override = SubResource( 4 )
mesh = SubResource( 2 )
material/0 = null
[node name="CSGSphere" type="CSGSphere" parent="."]
transform = Transform( 4.9, 0, 0, 0, 3.64893, 0, 0, 0, 4.84088, -0.126031, -0.175355, -8.52605 )

View File

@ -3,23 +3,17 @@ extends Resource
class_name SummerDayEditable
var priority = 0
var modifier_layer = 0
var selected = false
var preference_number = 0
func _check_for_selection(event: InputEvent): # Virtual.
pass
func _interact(event: InputEvent): # Virtual.
pass
func _update_table(table: Image): # Virtual.
pass
func _is_point_included(point: Vector2) -> bool: # Virtual.
func _check_for_selection_candidate(event: InputEvent) -> bool: # Virtual.
return false
# Returns false if input was potentially meant for a different editable.
func _interact(event: InputEvent) -> bool: # Virtual.
return false
func _update_table(table: SummerDayTable): # Virtual.
pass

View File

@ -3,22 +3,36 @@ extends SummerDayEditable
class_name SummerDayEditableTube
func _check_for_selection(event: InputEvent): # Virtual.
pass
func _interact(event: InputEvent): # Virtual.
pass
func update_table():
pass # TODO: Do I even need this?!
func _update_table(table: Image): # Virtual.
pass
func _is_point_included(point: Vector2) -> bool: # Virtual.
return false
export(PoolVector2Array) var vertices = PoolVector2Array([
Vector2(-0.4, -0.4),
Vector2(0.1, -0.4),
Vector2(0.1, 0.1),
Vector2(-0.4, 0.1),
Vector2(-0.1, -0.1),
Vector2(0.4, -0.1),
Vector2(0.4, 0.4),
Vector2(-0.1, 0.4),
])
func _check_for_selection_candidate(event: InputEvent) -> bool: # Virtual.
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
return _is_point_included(event.position)
return false
func _interact(event: InputEvent) -> bool: # Virtual.
return false
func _update_table(table: SummerDayTable): # Virtual.
pass
func _is_point_included(point: Vector2) -> bool: # Private.
var convex_hull = Geometry.convex_hull_2d(vertices)
return Geometry.is_point_in_polygon(point, convex_hull)

View File

@ -5,7 +5,18 @@ class_name SummerDayCell
export(Array, Resource) var editable_list := []
var selected = []
func _pass_input(event: InputEvent): # Virtual.
for i in editable_list:
i._check_for_selection(event)
var block_selection = false
if selected.size() == 1:
var success = selected[0]._interact(event)
if success:
block_selection = true
if !block_selection:
selected.clear()
for i in editable_list:
if i._check_for_selection_candidate(event):
selected.append(i)
print("YOU CLICKED!!")

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://addons/summer_day/user_interface/canvas/canvas.gd" type="Script" id=1]
[ext_resource path="res://addons/summer_day/user_interface/canvas/mesh_container.gd" type="Script" id=2]
[ext_resource path="res://addons/summer_day/user_interface/canvas/rendering/interaction_hint.gd" type="Script" id=3]
[sub_resource type="StyleBoxFlat" id=3]
bg_color = Color( 0.180392, 0.172549, 0.203922, 1 )
@ -24,6 +25,22 @@ environment = SubResource( 1 )
[sub_resource type="CanvasItemMaterial" id=5]
blend_mode = 3
[sub_resource type="Shader" id=6]
code = "shader_type spatial;
render_mode blend_mix, depth_draw_opaque, unshaded, depth_test_disable;
void fragment() {
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r;
float weight = clamp((FRAGCOORD.z - depth) * float(0xFFFFFF), 0.0, 0.66);
vec3 screen_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
ALBEDO = mix(ALBEDO, screen_color, weight);
}"
[sub_resource type="ShaderMaterial" id=7]
render_priority = 1
shader = SubResource( 6 )
[node name="Canvas" type="PanelContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
@ -85,6 +102,10 @@ invert_enable = true
invert_border = 1000.0
polygon = PoolVector2Array( 0, 0, 1.77778, 0, 1.77778, 1, 0, 1 )
[node name="InteractionHint" type="ImmediateGeometry" parent="Render/RenderLayer"]
material_override = SubResource( 7 )
script = ExtResource( 3 )
[node name="ForegroundLayer" type="Viewport" parent="Render" groups=["SummerDayCanvasTransform"]]
size = Vector2( 998, 574 )
transparent_bg = true
@ -93,8 +114,6 @@ usage = 0
render_target_update_mode = 3
gui_disable_input = true
[node name="EditHints" type="ImmediateGeometry" parent="Render/ForegroundLayer"]
[node name="Label" type="Label" parent="Render"]
margin_right = 40.0
margin_bottom = 14.0

View File

@ -0,0 +1,38 @@
tool
extends ImmediateGeometry
class_name SummerDayInteractionHint
var canvas_state: SummerDayCanvasState # Provided through Canvas.
func draw_dot(position: Vector3, color: Color):
var transformed_position = canvas_state.clip_space_view_transform.xform(
position
)
var radius = 3.0
var vertex_count = 12.0
begin(Mesh.PRIMITIVE_TRIANGLE_FAN)
set_color(color)
for i in range(vertex_count):
var weight = i / vertex_count
var offset = Vector3(sin(weight * TAU), cos(weight * TAU), 0.0)
add_vertex(transformed_position + offset)
end()
func draw_line(position_1: Vector3, position_2: Vector3, color: Color):
var transformed_position_1 = canvas_state.clip_space_view_transform.xform(
position_1
)
var transformed_position_2 = canvas_state.clip_space_view_transform.xform(
position_2
)
begin(Mesh.PRIMITIVE_LINES)
set_color(color)
add_vertex(transformed_position_1)
add_vertex(transformed_position_2)
end()

View File

@ -0,0 +1,4 @@
extends Node
#var canvas_state: SummerDayCanvasState

View File

@ -94,6 +94,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://addons/summer_day/tools/canvas/general_use/hand.gd"
}, {
"base": "ImmediateGeometry",
"class": "SummerDayInteractionHint",
"language": "GDScript",
"path": "res://addons/summer_day/user_interface/canvas/rendering/interaction_hint.gd"
}, {
"base": "Control",
"class": "SummerDayMainScreen",
"language": "GDScript",
@ -202,6 +207,7 @@ _global_script_class_icons={
"SummerDayEditableTube": "",
"SummerDayFreeTransformCanvasTool": "",
"SummerDayHandCanvasTool": "",
"SummerDayInteractionHint": "",
"SummerDayMainScreen": "",
"SummerDayMathHelper": "",
"SummerDayMatrix4": "",