Skip to content

Commit

Permalink
update some
Browse files Browse the repository at this point in the history
  • Loading branch information
HK-SHAO committed Oct 28, 2022
1 parent 52d7544 commit 22c33a9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _global_script_classes=[{
"base": "Control",
"class": &"DrawBoard",
"language": &"GDScript",
"path": "res://test/script/draw_board.gd"
"path": "res://shared/script/DrawBoard.gd"
}, {
"base": "Camera3D",
"class": &"FreeCamera3D",
Expand Down
22 changes: 9 additions & 13 deletions app/test/script/draw_board.gd → app/shared/script/DrawBoard.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class_name DrawBoard

extends Control

@export var default_line: Line2D

@export_range(0, 2) var smooth: float = 0.2
@export_range(0, 100000) var sensitivity: float = 5000

Expand All @@ -25,12 +27,10 @@ func _input(event: InputEvent) -> void:
_input_event_mouse_button(event)
elif event is InputEventKey:
_input_event_key(event)
pass

func _input_event_mouse_motion(event: InputEventMouseMotion) -> void:
if is_left_pressed:
brush_position = event.position
pass

func _input_event_mouse_button(event: InputEventMouseButton) -> void:
var is_pressed := event.is_pressed()
Expand All @@ -44,17 +44,19 @@ func _input_event_mouse_button(event: InputEventMouseButton) -> void:
brush_position = event.position
ink_position = event.position
point_position = event.position
pass

func _input_event_key(event: InputEventKey) -> void:
match event.keycode:
KEY_SPACE:
# 清空所有线条
for line in lines.get_children():
line.queue_free()
pass

func add_line2d() -> Line2D:
var line2d := Line2D.new()
var line2d := default_line.duplicate() \
if is_instance_valid(default_line) \
else Line2D.new()

lines.add_child(line2d)
return line2d

Expand All @@ -63,7 +65,6 @@ func add_point(point: Vector2) -> void:
cur_line_2d.add_point(point)
else:
cur_line_2d = add_line2d()
pass

func update_ink(delta: float) -> void:
var d := brush_position.distance_squared_to(ink_position)
Expand All @@ -78,17 +79,12 @@ func update_ink(delta: float) -> void:
ink_position += delta_position * delta

func update_point() -> void:
var d = ink_position.distance_squared_to(point_position)
var d := ink_position.distance_squared_to(point_position)

point_position = ink_position

if d > 0:
add_point(point_position)
if d > 0: add_point(point_position)

func _process(delta: float) -> void:
if is_left_pressed:

update_ink(delta)
update_point()

pass
8 changes: 4 additions & 4 deletions app/shared/script/FreeCamera3D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func _input(event: InputEvent):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

MOUSE_BUTTON_WHEEL_UP: # increase fly velocity
velocity = clamp(velocity * speed_scale, min_speed, max_speed)
max_speed *= speed_scale
MOUSE_BUTTON_WHEEL_DOWN: # decrease fly velocity
velocity = clamp(velocity / speed_scale, min_speed, max_speed)
max_speed /= speed_scale

func set_rotation(rot: Vector3):
rotation = rot
Expand All @@ -57,10 +57,10 @@ func _process(delta: float) -> void:


if direction.length() != 0:
_velocity += (max_speed - _velocity) * delta * 0.01
_velocity += (max_speed - _velocity) * delta * 0.1 * sensitivity
_translate = direction * _velocity * delta
else:
_velocity = velocity;
_velocity = min_speed;
_translate -= _translate * delta * smooth


Expand Down
13 changes: 9 additions & 4 deletions app/test/scene/test_camera_scene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,23 @@ camera = NodePath("../../Node3D/FreeCamera3D")

[node name="Node3D" type="Node3D" parent="."]

[node name="WorldEnvironment" type="WorldEnvironment" parent="Node3D"]
[node name="Node3D" type="Node3D" parent="Node3D"]
process_mode = 4
visible = false

[node name="WorldEnvironment" type="WorldEnvironment" parent="Node3D/Node3D"]
environment = SubResource("Environment_dw3fv")

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Node3D"]
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Node3D/Node3D"]
transform = Transform3D(-0.866024, -0.433016, 0.250001, 0, 0.499998, 0.866026, -0.500003, 0.749999, -0.43301, 0, 0, 0)
shadow_enabled = true

[node name="MeshInstance3D" type="MeshInstance3D" parent="Node3D"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Node3D/Node3D"]
transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0)
visible = false
material_override = SubResource("ShaderMaterial_cgygt")
mesh = SubResource("BoxMesh_782f1")
skeleton = NodePath("../..")

[node name="FreeCamera3D" type="Camera3D" parent="Node3D"]
script = ExtResource("6_nof40")
Expand Down
22 changes: 16 additions & 6 deletions app/test/scene/test_drawer_scene.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[gd_scene load_steps=6 format=3 uid="uid://cnfrgfxr15oog"]
[gd_scene load_steps=8 format=3 uid="uid://mmb27hhk2jm6"]

[ext_resource type="Script" path="res://shared/script/tool/tool_node2d_center.gd" id="2_3qj1q"]
[ext_resource type="Script" path="res://shared/script/action/action_transparent_background.gd" id="2_g5dwt"]
[ext_resource type="Script" path="res://test/script/draw_board.gd" id="3_04od2"]
[ext_resource type="Shader" path="res://test/shader/test_drawer_line.gdshader" id="3_fun8t"]
[ext_resource type="Script" path="res://shared/script/DrawBoard.gd" id="4_2hhjp"]
[ext_resource type="Texture2D" uid="uid://dq8b8n1vxlo8" path="res://shared/image/icon.svg" id="4_bjgwy"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_lqxjv"]
shader = ExtResource("3_fun8t")

[sub_resource type="GDScript" id="GDScript_ms0kl"]
script/source = "extends Node2D

Expand Down Expand Up @@ -48,8 +52,6 @@ position = Vector2(640, 360)
[node name="tool_node2d_center" type="Node" parent="Node2D"]
script = ExtResource("2_3qj1q")

[node name="Line2D" type="Line2D" parent="Node2D"]

[node name="Button" type="Button" parent="Node2D"]
anchors_preset = 8
anchor_left = 0.5
Expand All @@ -64,14 +66,22 @@ grow_horizontal = 2
grow_vertical = 2
text = "123456"

[node name="DrawBoard" type="Control" parent="."]
[node name="Line2D" type="Line2D" parent="."]
material = SubResource("ShaderMaterial_lqxjv")
width = 20.0
joint_mode = 2
begin_cap_mode = 2
end_cap_mode = 2

[node name="DrawBoard" type="Control" parent="." node_paths=PackedStringArray("default_line")]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("3_04od2")
script = ExtResource("4_2hhjp")
default_line = NodePath("../Line2D")

[node name="Test" type="Node2D" parent="DrawBoard"]
visible = false
Expand Down
3 changes: 1 addition & 2 deletions app/test/shader/camera_cube_4d.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,11 @@ void fragment() {

vec4 tot = vec4(0.0);

vec2 p = UV;

float seed = FRAGCOORD.x + FRAGCOORD.y*131.1 + TIME;

// ray direction
vec3 rd = ca * normalize( -vec3(p.xy, 1.0) );
vec3 rd = ca * normalize( -vec3(UV.xy, 1.0) );

// render
vec4 col = render( ro, rd, seed, v );
Expand Down
6 changes: 6 additions & 0 deletions app/test/shader/test_drawer_line.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
shader_type canvas_item;

void fragment() {
COLOR.r = 1.0;
COLOR.g = 0.0;
}

0 comments on commit 22c33a9

Please sign in to comment.