diff --git a/app/assets/models/ray/ray.mtl b/app/assets/models/ray/ray.mtl new file mode 100644 index 0000000..1fbd395 --- /dev/null +++ b/app/assets/models/ray/ray.mtl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c0deab1be805622c3d25c36e1d164d777f6b4929954ba4326044caec70d2598 +size 231 diff --git a/app/assets/models/ray/ray.obj b/app/assets/models/ray/ray.obj new file mode 100644 index 0000000..df62d61 --- /dev/null +++ b/app/assets/models/ray/ray.obj @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e2aac3c602e96bd6e467b061b242dda2de37879af7805be3743f2954d6b02d7 +size 36454 diff --git a/app/assets/models/ray/ray.obj.import b/app/assets/models/ray/ray.obj.import new file mode 100644 index 0000000..b65a0d2 --- /dev/null +++ b/app/assets/models/ray/ray.obj.import @@ -0,0 +1,22 @@ +[remap] + +importer="wavefront_obj" +importer_version=1 +type="Mesh" +uid="uid://d3kriab522o2w" +path="res://.godot/imported/ray.obj-93386a124e8f29fa7d3c4cb30885a2c5.mesh" + +[deps] + +files=["res://.godot/imported/ray.obj-93386a124e8f29fa7d3c4cb30885a2c5.mesh"] + +source_file="res://assets/models/ray/ray.obj" +dest_files=["res://.godot/imported/ray.obj-93386a124e8f29fa7d3c4cb30885a2c5.mesh", "res://.godot/imported/ray.obj-93386a124e8f29fa7d3c4cb30885a2c5.mesh"] + +[params] + +generate_tangents=true +scale_mesh=Vector3(1, 1, 1) +offset_mesh=Vector3(0, 0, 0) +optimize_mesh=true +force_disable_mesh_compression=false diff --git a/app/assets/models/ray/ray.png b/app/assets/models/ray/ray.png new file mode 100644 index 0000000..0b0a66e --- /dev/null +++ b/app/assets/models/ray/ray.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42ff953ca7804b3e87d65a902f98106222e229dcf81de55badd89be19c527768 +size 77255 diff --git a/app/assets/models/ray/ray.png.import b/app/assets/models/ray/ray.png.import new file mode 100644 index 0000000..2ea9df1 --- /dev/null +++ b/app/assets/models/ray/ray.png.import @@ -0,0 +1,36 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cy5dna78q6tn6" +path.s3tc="res://.godot/imported/ray.png-2e419c9bce172c50b153cf9d3bb59d1c.s3tc.ctex" +path.etc2="res://.godot/imported/ray.png-2e419c9bce172c50b153cf9d3bb59d1c.etc2.ctex" +metadata={ +"imported_formats": ["s3tc_bptc", "etc2_astc"], +"vram_texture": true +} + +[deps] + +source_file="res://assets/models/ray/ray.png" +dest_files=["res://.godot/imported/ray.png-2e419c9bce172c50b153cf9d3bb59d1c.s3tc.ctex", "res://.godot/imported/ray.png-2e419c9bce172c50b153cf9d3bb59d1c.etc2.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/app/assets/ray.blend b/app/assets/ray.blend new file mode 100644 index 0000000..1d9a395 --- /dev/null +++ b/app/assets/ray.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:951598e139ce7b692e292e24d89ebbf37a86093a15524f4b650b30e95b220c44 +size 934416 diff --git a/app/assets/ray.blend1 b/app/assets/ray.blend1 new file mode 100644 index 0000000..a2cab8c Binary files /dev/null and b/app/assets/ray.blend1 differ diff --git a/app/content/system/raycast/raycast.gd b/app/content/system/raycast/raycast.gd index 89535f6..4f9b2f2 100644 --- a/app/content/system/raycast/raycast.gd +++ b/app/content/system/raycast/raycast.gd @@ -1,7 +1,7 @@ extends RayCast3D -const Pointer = preload("res://lib/utils/pointer/pointer.gd") -const Initiator = preload("res://lib/utils/pointer/initiator.gd") +const Pointer = preload ("res://lib/utils/pointer/pointer.gd") +const Initiator = preload ("res://lib/utils/pointer/initiator.gd") @onready var cursor: Node3D = $Cursor @onready var decal: Decal = $Decal @@ -10,6 +10,7 @@ const Initiator = preload("res://lib/utils/pointer/initiator.gd") @export var with_decal: bool = false @onready var pointer: Pointer +@onready var visual_ray: MeshInstance3D = $Ray var _event_type_map = { "trigger_click": Initiator.EventType.TRIGGER, @@ -39,12 +40,21 @@ func _physics_process(_delta): func _handle_cursor(): var collider = get_collider() + var distance = get_collision_point().distance_to(global_position) if collider == null: cursor.visible = false + visual_ray.visible = true + visual_ray.scale.y = 1 if with_decal: decal.visible = true return + if distance < 0.15: + visual_ray.visible = false + else: + visual_ray.visible = true + visual_ray.scale.y = clamp(distance * 2 - 0.1, 0.15, 1) + cursor.visible = true decal.visible = false cursor.global_transform.origin = get_collision_point() + get_collision_normal() * 0.001 # offset to avoid z-fighting diff --git a/app/content/system/raycast/raycast.gdshader b/app/content/system/raycast/raycast.gdshader new file mode 100644 index 0000000..2f473d8 --- /dev/null +++ b/app/content/system/raycast/raycast.gdshader @@ -0,0 +1,13 @@ +// NOTE: Shader automatically converted from Godot Engine 4.2.stable's StandardMaterial3D. + +shader_type spatial; +render_mode cull_back, unshaded; +uniform vec4 albedo : source_color; +uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable; + +void fragment() { + vec2 base_uv = UV; + vec4 albedo_tex = texture(texture_albedo,base_uv); + ALBEDO = albedo.rgb * albedo_tex.rgb; + ALPHA *= albedo.a * albedo_tex.a; +} diff --git a/app/content/system/raycast/raycast.tscn b/app/content/system/raycast/raycast.tscn index 55e4b3d..0efc290 100644 --- a/app/content/system/raycast/raycast.tscn +++ b/app/content/system/raycast/raycast.tscn @@ -1,12 +1,22 @@ -[gd_scene load_steps=3 format=3 uid="uid://d3f8glx1xgm5w"] +[gd_scene load_steps=7 format=3 uid="uid://d3f8glx1xgm5w"] [ext_resource type="Texture2D" uid="uid://bl33klueufwja" path="res://assets/materials/pointer.png" id="1_2f2iv"] [ext_resource type="Script" path="res://content/system/raycast/raycast.gd" id="1_gp8nv"] +[ext_resource type="Shader" path="res://content/system/raycast/raycast.gdshader" id="3_lpfe7"] +[ext_resource type="Texture2D" uid="uid://cy5dna78q6tn6" path="res://assets/models/ray/ray.png" id="4_fe8o8"] +[ext_resource type="ArrayMesh" uid="uid://d3kriab522o2w" path="res://assets/models/ray/ray.obj" id="5_3o4gy"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ov0gt"] +render_priority = 0 +shader = ExtResource("3_lpfe7") +shader_parameter/albedo = Color(1, 1, 1, 1) +shader_parameter/texture_albedo = ExtResource("4_fe8o8") [node name="Raycast" type="RayCast3D"] -transform = Transform3D(0.999999, -1.39624e-11, 0, 9.48108e-12, 0.999999, 0, 0, 4.54747e-13, 0.999998, -0.000467122, 0.00228411, -0.0016689) +transform = Transform3D(0.999999, -1.39624e-11, 0, 9.48108e-12, 0.999999, 0, 0, 4.54747e-13, 0.999998, 0, 0, 0) target_position = Vector3(0, 0, -5) collision_mask = 19 +debug_shape_custom_color = Color(0, 0, 0, 0) script = ExtResource("1_gp8nv") [node name="Decal" type="Decal" parent="."] @@ -22,3 +32,8 @@ lower_fade = 0.000919435 transform = Transform3D(0.03, 2.71051e-20, 0, -5.42101e-20, 0.03, -2.03288e-21, -2.46521e-33, 2.5411e-21, 0.03, 0, 0, 0) pixel_size = 0.001 texture = ExtResource("1_2f2iv") + +[node name="Ray" type="MeshInstance3D" parent="."] +transform = Transform3D(1, -1.39624e-11, -6.10317e-19, 0, -4.37114e-08, 1, -1.39624e-11, -1, -4.37114e-08, 0, 0, -0.0182334) +material_override = SubResource("ShaderMaterial_ov0gt") +mesh = ExtResource("5_3o4gy")