commit
5f414434d8
46
app/assets/materials/grid.gdshader
Normal file
46
app/assets/materials/grid.gdshader
Normal file
|
@ -0,0 +1,46 @@
|
|||
shader_type spatial;
|
||||
|
||||
render_mode unshaded, cull_back;
|
||||
|
||||
uniform float dot_size: hint_range(0.0, 1.0, 0.01) = 0.5;
|
||||
uniform float dot_falloff: hint_range(0.0, 0.4, 0.001) = 0.1;
|
||||
uniform float size: hint_range(1.0, 32.0, 0.1) = 16.0;
|
||||
uniform vec2 dot_offset = vec2(0.0);
|
||||
uniform int supersampling: hint_range(0, 10, 1) = 1;
|
||||
|
||||
vec2 random(vec2 st){
|
||||
return vec2(fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123), fract(sin(dot(st.xy, vec2(-40.644))) * 87502.29935));
|
||||
}
|
||||
|
||||
float sdf_sphere(vec2 position, float center_dist) {
|
||||
return length(position) - max(0.0, dot_size / size - center_dist * dot_falloff);
|
||||
}
|
||||
|
||||
vec2 sdf_repeat(vec2 position) {
|
||||
float inv_size = 1.0 / (size * 2.0);
|
||||
return fract(position * size) / size - inv_size;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
float total_dist = 0.0;
|
||||
|
||||
for(int i = 0; i < supersampling; i++) {
|
||||
float center_dist = distance(UV, vec2(0.5, 0.5));
|
||||
vec2 rand = random(vec2(float(i))) * 0.004 * (0.5 - center_dist);
|
||||
float dist = sdf_sphere(sdf_repeat(UV - dot_offset - rand), center_dist);
|
||||
if (dist <= 0.0) {
|
||||
total_dist += 1.0 / float(supersampling);
|
||||
}
|
||||
}
|
||||
|
||||
ALBEDO = vec3(1.0);
|
||||
ALPHA = total_dist;
|
||||
|
||||
//if(dist <= 0.0) {
|
||||
//ALBEDO = vec3(1.0);
|
||||
//} else {
|
||||
//ALBEDO = vec3(1.0);
|
||||
//ALPHA = dist;
|
||||
//}
|
||||
}
|
||||
|
13
app/assets/materials/grid.tres
Normal file
13
app/assets/materials/grid.tres
Normal file
|
@ -0,0 +1,13 @@
|
|||
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://bb4kgiocswfv7"]
|
||||
|
||||
[ext_resource type="Shader" path="res://assets/materials/grid.gdshader" id="1_oebjc"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = true
|
||||
render_priority = 8
|
||||
shader = ExtResource("1_oebjc")
|
||||
shader_parameter/dot_size = 0.1
|
||||
shader_parameter/dot_falloff = 0.02
|
||||
shader_parameter/size = 10.0
|
||||
shader_parameter/dot_offset = Vector2(0, 0)
|
||||
shader_parameter/supersampling = 8
|
|
@ -36,6 +36,11 @@ unique_name_in_owner = true
|
|||
unique_name_in_owner = true
|
||||
transform = Transform3D(0.999999, -1.39633e-11, 0, 9.48075e-12, 1, 0, 0, 0, 1, -0.355145, 0.550439, -0.477945)
|
||||
|
||||
[node name="AutoHandtracker" parent="XROrigin3D/XRControllerLeft" index="2"]
|
||||
applymiddlefingerfix = null
|
||||
applyscaling = null
|
||||
coincidewristorknuckle = null
|
||||
|
||||
[node name="IndexTip" parent="XROrigin3D/XRControllerLeft" index="4"]
|
||||
transform = Transform3D(0.967526, 0.252326, -0.0150302, -0.0150302, 0.116784, 0.993043, 0.252326, -0.960569, 0.116784, -0.00665802, 0.0427912, -0.169868)
|
||||
|
||||
|
|
|
@ -23,7 +23,20 @@ const Miniature = preload ("res://content/system/miniature/miniature.gd")
|
|||
@onready var ray: RayCast3D = $Raycast
|
||||
@onready var quick_actions = $Palm/QuickActions
|
||||
|
||||
var hand_active = false
|
||||
@export var show_grid = false:
|
||||
set(value):
|
||||
show_grid = value
|
||||
|
||||
if ray != null:
|
||||
ray.with_grid = value
|
||||
|
||||
var hand_active = false:
|
||||
set(value):
|
||||
hand_active = value
|
||||
|
||||
if pointer != null:
|
||||
pointer.set_physics_process(value)
|
||||
|
||||
var initiator: Initiator = Initiator.new()
|
||||
var collide: Collide
|
||||
var pointer: Pointer
|
||||
|
|
|
@ -39,6 +39,9 @@ is_right = false
|
|||
|
||||
[node name="AutoHandtracker" parent="." instance=ExtResource("4_oe7fv")]
|
||||
visible = false
|
||||
applymiddlefingerfix = null
|
||||
applyscaling = null
|
||||
coincidewristorknuckle = null
|
||||
visiblehandtrackskeleton = false
|
||||
enableautotracker = false
|
||||
|
||||
|
|
|
@ -16,7 +16,19 @@ const Miniature = preload ("res://content/system/miniature/miniature.gd")
|
|||
@onready var thumb_tip = $ThumbTip
|
||||
@onready var middle_tip = $MiddleTip
|
||||
|
||||
var hand_active = false
|
||||
@export var show_grid = false:
|
||||
set(value):
|
||||
show_grid = value
|
||||
|
||||
if ray != null:
|
||||
ray.with_grid = value
|
||||
|
||||
var hand_active = false:
|
||||
set(value):
|
||||
hand_active = value
|
||||
|
||||
if pointer != null:
|
||||
pointer.set_physics_process(value)
|
||||
var initiator: Initiator = Initiator.new()
|
||||
var collide: Collide
|
||||
var pointer: Pointer
|
||||
|
@ -34,6 +46,8 @@ func _ready():
|
|||
EventSystem.emit_action(action_name, false, true)
|
||||
)
|
||||
|
||||
_setup_hand()
|
||||
|
||||
func _setup_hand():
|
||||
TouchManager.add_finger(Finger.Type.INDEX_RIGHT, $IndexTip/TouchArea)
|
||||
|
||||
|
|
|
@ -27,16 +27,16 @@ mesh = SubResource("BoxMesh_ir3co")
|
|||
|
||||
[node name="Raycast" parent="." instance=ExtResource("1_3p68p")]
|
||||
|
||||
[node name="hand_r" parent="." instance=ExtResource("2_kex6u")]
|
||||
|
||||
[node name="mesh_Hand_R" parent="hand_r/Armature/Skeleton3D" index="0"]
|
||||
material_override = ExtResource("4_vhkya")
|
||||
|
||||
[node name="AutoHandtracker" parent="." instance=ExtResource("3_pjmb2")]
|
||||
visible = false
|
||||
visiblehandtrackskeleton = false
|
||||
enableautotracker = false
|
||||
|
||||
[node name="hand_r" parent="." instance=ExtResource("2_kex6u")]
|
||||
|
||||
[node name="mesh_Hand_R" parent="hand_r/Armature/Skeleton3D" index="0"]
|
||||
material_override = ExtResource("4_vhkya")
|
||||
|
||||
[node name="IndexTip" type="BoneAttachment3D" parent="."]
|
||||
transform = Transform3D(0.967526, -0.252326, 0.0150302, 0.0150302, 0.116784, 0.993043, -0.252326, -0.960569, 0.116784, 0.00665802, 0.0427913, -0.169868)
|
||||
bone_name = "Index_Tip_R"
|
||||
|
|
|
@ -73,6 +73,9 @@ func edit_room(room_name):
|
|||
if room == editing_room:
|
||||
return
|
||||
|
||||
App.controller_left.show_grid = false
|
||||
App.controller_right.show_grid = false
|
||||
|
||||
if editing_room != null:
|
||||
editing_room.editable = false
|
||||
editing_room = null
|
||||
|
@ -80,6 +83,8 @@ func edit_room(room_name):
|
|||
if room != null:
|
||||
room.editable = true
|
||||
editing_room = room
|
||||
App.controller_left.show_grid = true
|
||||
App.controller_right.show_grid = true
|
||||
|
||||
func is_valid_room(room_name):
|
||||
var room = find_room(room_name)
|
||||
|
|
|
@ -7,9 +7,12 @@ const Initiator = preload ("res://lib/utils/pointer/initiator.gd")
|
|||
@onready var default_cursor: Sprite3D = $Cursor/DefaultCursor
|
||||
@onready var retro_cursor: Sprite3D = $Cursor/RetroCursor
|
||||
@onready var decal: Decal = $Decal
|
||||
@onready var grid: MeshInstance3D = $Grid
|
||||
@onready var wall_collider: RayCast3D = $WallCollider
|
||||
|
||||
@export var is_right: bool = true
|
||||
@export var with_decal: bool = false
|
||||
@export var with_grid: bool = false
|
||||
|
||||
@onready var pointer: Pointer
|
||||
@onready var visual_ray: MeshInstance3D = $Ray
|
||||
|
@ -38,17 +41,34 @@ func _ready():
|
|||
)
|
||||
|
||||
R.effect(func(_arg):
|
||||
match Store.settings.state.cursor_style:
|
||||
1:
|
||||
default_cursor.visible=false
|
||||
retro_cursor.visible=true
|
||||
0, _:
|
||||
default_cursor.visible=true
|
||||
retro_cursor.visible=false
|
||||
var style=Store.settings.state.cursor_style
|
||||
|
||||
default_cursor.visible=style == 0
|
||||
retro_cursor.visible=style == 1
|
||||
)
|
||||
|
||||
func _physics_process(_delta):
|
||||
_handle_cursor()
|
||||
_handle_grid()
|
||||
|
||||
func _process(delta):
|
||||
if grid.visible:
|
||||
grid.material_override.set_shader_parameter("dot_offset", TransformTools.plane_2d_coords(grid.global_transform) / grid.mesh.size.x)
|
||||
|
||||
func _handle_grid():
|
||||
var collider = wall_collider.get_collider()
|
||||
|
||||
if collider == null:
|
||||
grid.visible = false
|
||||
|
||||
grid.visible = with_grid
|
||||
|
||||
grid.global_position = wall_collider.get_collision_point() + wall_collider.get_collision_normal() * 0.01
|
||||
|
||||
if abs(wall_collider.get_collision_normal().dot(Vector3.UP)) > 0.9:
|
||||
grid.global_transform.basis = Basis.looking_at(wall_collider.get_collision_normal(), Vector3.FORWARD, true)
|
||||
else:
|
||||
grid.global_transform.basis = Basis.looking_at(wall_collider.get_collision_normal(), Vector3.UP, true)
|
||||
|
||||
func _handle_cursor():
|
||||
var collider = get_collider()
|
||||
|
@ -69,6 +89,7 @@ func _handle_cursor():
|
|||
|
||||
cursor.visible = true
|
||||
decal.visible = false
|
||||
|
||||
cursor.global_transform.origin = get_collision_point() + get_collision_normal() * 0.001 # offset to avoid z-fighting
|
||||
|
||||
if abs(get_collision_normal().dot(Vector3.UP)) > 0.9:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dscp8x0ari57n"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://dscp8x0ari57n"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bl33klueufwja" path="res://assets/cursors/pointer.png" id="1_2f2iv"]
|
||||
[ext_resource type="Script" path="res://content/system/raycast/raycast.gd" id="1_gp8nv"]
|
||||
|
@ -6,6 +6,7 @@
|
|||
[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"]
|
||||
[ext_resource type="Material" uid="uid://bb4kgiocswfv7" path="res://assets/materials/grid.tres" id="7_tnbkv"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ov0gt"]
|
||||
render_priority = 0
|
||||
|
@ -13,6 +14,9 @@ shader = ExtResource("3_lpfe7")
|
|||
shader_parameter/albedo = Color(1, 1, 1, 1)
|
||||
shader_parameter/texture_albedo = ExtResource("4_fe8o8")
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_cq16e"]
|
||||
orientation = 2
|
||||
|
||||
[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, 0, 0)
|
||||
target_position = Vector3(0, 0, -5)
|
||||
|
@ -49,3 +53,11 @@ texture = ExtResource("3_f5ibs")
|
|||
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")
|
||||
|
||||
[node name="Grid" type="MeshInstance3D" parent="."]
|
||||
material_override = ExtResource("7_tnbkv")
|
||||
mesh = SubResource("PlaneMesh_cq16e")
|
||||
|
||||
[node name="WallCollider" type="RayCast3D" parent="."]
|
||||
target_position = Vector3(0, 0, -10)
|
||||
collision_mask = 16
|
||||
|
|
|
@ -60,7 +60,7 @@ func send_data(data: PackedByteArray):
|
|||
stream.encode_s8(0, handler_id)
|
||||
stream.append_array(data)
|
||||
|
||||
api.send_raw(stream)
|
||||
api.connection.send_raw(stream)
|
||||
|
||||
func handle_message(message: Dictionary):
|
||||
if message["type"] != "event":
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
class_name TransformTools
|
||||
|
||||
static func plane_2d_coords(transform: Transform3D) -> Vector2:
|
||||
var point = transform.origin
|
||||
|
||||
transform.origin = Vector3.ZERO
|
||||
point = transform.inverse() * point
|
||||
|
||||
return Vector2( - point.x, point.y)
|
||||
|
||||
## Calculate the transform that would transform the source position, direction and up vector to the target position, direction and up vector
|
||||
## Basically a bit more fancy Inputs for a Transform3D
|
||||
static func calc_delta_transform(source_pos: Vector3, source_dir: Vector3, source_up: Vector3, target_pos: Vector3, target_dir: Vector3, target_up: Vector3) -> Transform3D:
|
||||
|
|
9
app/test/content/grid_shader.gd
Normal file
9
app/test/content/grid_shader.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
@tool
|
||||
extends Node3D
|
||||
|
||||
const GridShader = preload ("res://assets/materials/grid.tres")
|
||||
|
||||
@onready var mesh = $MeshInstance3D
|
||||
|
||||
func _process(_delta):
|
||||
GridShader.set_shader_parameter("dot_offset", TransformTools.plane_2d_coords(mesh.global_transform))
|
15
app/test/content/grid_shader.tscn
Normal file
15
app/test/content/grid_shader.tscn
Normal file
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://d26xg5okbaen6"]
|
||||
|
||||
[ext_resource type="Script" path="res://test/content/grid_shader.gd" id="1_jgxlt"]
|
||||
[ext_resource type="Material" uid="uid://bb4kgiocswfv7" path="res://assets/materials/grid.tres" id="2_siin6"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_atwo6"]
|
||||
size = Vector2(1, 1)
|
||||
|
||||
[node name="Node3D" type="Node3D"]
|
||||
script = ExtResource("1_jgxlt")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(-0.843227, -0.537538, -0.00456947, -0.18903, 0.28855, 0.93862, -0.503225, 0.792333, -0.344923, 0.968812, 1.30895, -0.0715666)
|
||||
material_override = ExtResource("2_siin6")
|
||||
mesh = SubResource("PlaneMesh_atwo6")
|
Loading…
Reference in New Issue
Block a user