Skip to content

Commit

Permalink
Fixes for the EasySDF editor
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Aug 26, 2024
1 parent 6da1ad6 commit 027e56b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 49 deletions.
4 changes: 2 additions & 2 deletions material_maker/windows/sdf_builder/gizmo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ mode = 3
[node name="ArrowY" parent="." instance=ExtResource("1")]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0)
material = SubResource("5")
mode = 1
mode = 3

[node name="ArrowZ" parent="." instance=ExtResource("1")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0)
material = SubResource("6")
mode = 1
mode = 3

[connection signal="move" from="ArrowX" to="." method="_on_Arrow_move"]
[connection signal="rotate" from="ArrowX" to="." method="_on_Arrow_rotate"]
Expand Down
7 changes: 4 additions & 3 deletions material_maker/windows/sdf_builder/gizmo_arrow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func _ready():
func set_material(m):
material = m
if is_inside_tree():
$Arrow.set_surface_override_material(0, material)
$Torus.set_surface_override_material(0, material)
for mesh in [$Arrow, $Arrow/Tip, $Torus]:
mesh.set_surface_override_material(0, material)

func _on_TranslateArea_input_event(camera, event, _position, _normal, _shape_idx):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
$Arrow.get_surface_override_material(0).set_shader_parameter("highlight", 0.1 if event.pressed else 0.0)
for mesh in [$Arrow, $Arrow/Tip]:
$Arrow.get_surface_override_material(0).set_shader_parameter("highlight", 0.1 if event.pressed else 0.0)
elif event is InputEventMouseMotion and event.button_mask == MOUSE_BUTTON_MASK_LEFT:
var origin : Vector3 = global_transform * Vector3(0, 0, 0)
var end : Vector3 = global_transform * Vector3(1, 0, 0)
Expand Down
68 changes: 30 additions & 38 deletions material_maker/windows/sdf_builder/gizmo_arrow.tscn
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
[gd_scene load_steps=9 format=3 uid="uid://duqci7ecjbnyx"]
[gd_scene load_steps=8 format=3 uid="uid://duqci7ecjbnyx"]

[ext_resource type="Script" path="res://material_maker/windows/sdf_builder/gizmo_arrow.gd" id="1"]

[sub_resource type="StandardMaterial3D" id="3"]
shading_mode = 0
albedo_color = Color(1, 0, 0, 1)

[sub_resource type="StandardMaterial3D" id="1"]
resource_name = "None"
albedo_color = Color(0.8, 0.8, 0.8, 1)
metallic = 0.8

[sub_resource type="ArrayMesh" id="6"]
_surfaces = [{
"aabb": AABB(0, 0, 0, 0, 0, 0),
"format": 34359738368,
"material": SubResource("1"),
"name": "None",
"primitive": 5,
"uv_scale": Vector4(0, 0, 0, 0),
"vertex_count": 0,
"vertex_data": PackedByteArray()
}]

[sub_resource type="StandardMaterial3D" id="7"]
resource_name = "None"
albedo_color = Color(0.8, 0.8, 0.8, 1)
metallic = 0.8

[sub_resource type="ArrayMesh" id="8"]
_surfaces = [{
"aabb": AABB(0, 0, 0, 0, 0, 0),
"format": 34359738368,
"material": SubResource("7"),
"name": "None",
"primitive": 5,
"uv_scale": Vector4(0, 0, 0, 0),
"vertex_count": 0,
"vertex_data": PackedByteArray()
}]
[sub_resource type="CylinderMesh" id="CylinderMesh_mevst"]
top_radius = 0.025
bottom_radius = 0.025
height = 0.9
radial_segments = 12
rings = 1

[sub_resource type="CylinderMesh" id="CylinderMesh_ujfrw"]
top_radius = 0.0
bottom_radius = 0.05
height = 0.155
radial_segments = 12
rings = 1

[sub_resource type="TorusMesh" id="TorusMesh_33igc"]
inner_radius = 0.475
outer_radius = 0.525

[sub_resource type="CylinderShape3D" id="4"]
margin = 0.01
Expand All @@ -53,14 +37,22 @@ script = ExtResource("1")
material = SubResource("3")

[node name="Arrow" type="MeshInstance3D" parent="."]
mesh = SubResource("6")
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0.45, 0, 0)
mesh = SubResource("CylinderMesh_mevst")
skeleton = NodePath("../..")
material/0 = SubResource("3")
surface_material_override/0 = SubResource("3")

[node name="Tip" type="MeshInstance3D" parent="Arrow"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.07646e-08, 0.47504, 0)
mesh = SubResource("CylinderMesh_ujfrw")
skeleton = NodePath("../../..")
surface_material_override/0 = SubResource("3")

[node name="Torus" type="MeshInstance3D" parent="."]
mesh = SubResource("8")
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0)
mesh = SubResource("TorusMesh_33igc")
skeleton = NodePath("../..")
material/0 = SubResource("3")
surface_material_override/0 = SubResource("3")

[node name="TranslateArea" type="Area3D" parent="."]
input_capture_on_drag = true
Expand Down
2 changes: 1 addition & 1 deletion material_maker/windows/sdf_builder/preview_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var view_style : int = 0
func generate_preview_shader(source : MMGenBase.ShaderCode, _template) -> String:
var variables : Dictionary = {}
variables.GENERATED_GLOBALS = source.uniforms_as_strings()
variables.GENERATED_GLOBALS += "\n".join(PackedStringArray(source.globals))
variables.GENERATED_GLOBALS += source.get_globals_string()
variables.GENERATED_INSTANCE = source.defs
variables.GENERATED_CODE = source.code
if source.output_type == "sdf2d":
Expand Down
11 changes: 6 additions & 5 deletions material_maker/windows/sdf_builder/preview_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func set_generator(g : MMGenBase, o : int = 0, force : bool = false) -> void:
var material = plane.get_surface_override_material(0)
var variables : Dictionary = {}
variables.GENERATED_GLOBALS = source.uniforms_as_strings()
variables.GENERATED_GLOBALS += "\n".join(PackedStringArray(source.globals))
variables.GENERATED_GLOBALS += source.get_globals_string()
variables.GENERATED_INSTANCE = source.defs
variables.GENERATED_CODE = source.code
variables.GENERATED_OUTPUT = source.output_values.sdf3d
Expand All @@ -52,10 +52,11 @@ func set_generator(g : MMGenBase, o : int = 0, force : bool = false) -> void:
variables.COLOR_FCT = node_prefix+"_c"
variables.INDEX_UNIFORM = "p_"+node_prefix+"_index"
var shader_code : String = mm_preprocessor.preprocess_file("res://material_maker/windows/sdf_builder/preview_3d.gdshader", variables)
material = mm_deps.buffer_create_shader_material("preview_"+str(get_instance_id()), MMShaderMaterial.new(material), shader_code)
for u in source.uniforms:
if u.value:
material.set_shader_parameter(u.name, u.value)
material = await mm_deps.buffer_create_shader_material("preview_"+str(get_instance_id()), MMShaderMaterial.new(material), shader_code)
if material:
for u in source.uniforms:
if u.value:
material.set_shader_parameter(u.name, u.value)

var setup_controls_filter : String = ""
func setup_controls(filter : String = "") -> void:
Expand Down

0 comments on commit 027e56b

Please sign in to comment.