add ray guide

This commit is contained in:
Nitwel 2024-03-17 18:04:20 +01:00
parent f99cf1087e
commit 94fe9a1204
10 changed files with 112 additions and 4 deletions

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2c0deab1be805622c3d25c36e1d164d777f6b4929954ba4326044caec70d2598
size 231

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9e2aac3c602e96bd6e467b061b242dda2de37879af7805be3743f2954d6b02d7
size 36454

View File

@ -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

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:42ff953ca7804b3e87d65a902f98106222e229dcf81de55badd89be19c527768
size 77255

View File

@ -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

3
app/assets/ray.blend Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:951598e139ce7b692e292e24d89ebbf37a86093a15524f4b650b30e95b220c44
size 934416

BIN
app/assets/ray.blend1 Normal file

Binary file not shown.

View File

@ -10,6 +10,7 @@ const Initiator = preload("res://lib/utils/pointer/initiator.gd")
@export var with_decal: bool = false @export var with_decal: bool = false
@onready var pointer: Pointer @onready var pointer: Pointer
@onready var visual_ray: MeshInstance3D = $Ray
var _event_type_map = { var _event_type_map = {
"trigger_click": Initiator.EventType.TRIGGER, "trigger_click": Initiator.EventType.TRIGGER,
@ -39,12 +40,21 @@ func _physics_process(_delta):
func _handle_cursor(): func _handle_cursor():
var collider = get_collider() var collider = get_collider()
var distance = get_collision_point().distance_to(global_position)
if collider == null: if collider == null:
cursor.visible = false cursor.visible = false
visual_ray.visible = true
visual_ray.scale.y = 1
if with_decal: decal.visible = true if with_decal: decal.visible = true
return 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 cursor.visible = true
decal.visible = false decal.visible = false
cursor.global_transform.origin = get_collision_point() + get_collision_normal() * 0.001 # offset to avoid z-fighting cursor.global_transform.origin = get_collision_point() + get_collision_normal() * 0.001 # offset to avoid z-fighting

View File

@ -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;
}

View File

@ -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="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="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"] [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) target_position = Vector3(0, 0, -5)
collision_mask = 19 collision_mask = 19
debug_shape_custom_color = Color(0, 0, 0, 0)
script = ExtResource("1_gp8nv") script = ExtResource("1_gp8nv")
[node name="Decal" type="Decal" parent="."] [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) 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 pixel_size = 0.001
texture = ExtResource("1_2f2iv") 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")