mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
More work/experimentation on the mesh data resource editor.
This commit is contained in:
parent
4e071994f6
commit
ec558d1a16
19
game/addons/mesh_data_resource_editor/MDIEd.gd
Normal file
19
game/addons/mesh_data_resource_editor/MDIEd.gd
Normal file
@ -0,0 +1,19 @@
|
||||
tool
|
||||
extends PanelContainer
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func _unhandled_key_input(event : InputEventKey) -> void:
|
||||
#if event.key
|
||||
if event.scancode == KEY_G:
|
||||
#translate
|
||||
pass
|
||||
elif event.scancode == KEY_S:
|
||||
#scale? probably needs a differrent key
|
||||
pass
|
||||
elif event.scancode == KEY_R:
|
||||
#rotate
|
||||
pass
|
||||
|
||||
pass
|
60
game/addons/mesh_data_resource_editor/MDIEd.tscn
Normal file
60
game/addons/mesh_data_resource_editor/MDIEd.tscn
Normal file
@ -0,0 +1,60 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mesh_data_resource_editor/MDIEd.gd" type="Script" id=1]
|
||||
|
||||
[node name="MDIEd" type="PanelContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 593.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 20.0
|
||||
|
||||
[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_right = 19.0
|
||||
margin_bottom = 20.0
|
||||
text = "T"
|
||||
|
||||
[node name="Button2" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 23.0
|
||||
margin_right = 43.0
|
||||
margin_bottom = 20.0
|
||||
text = "R"
|
||||
|
||||
[node name="Button3" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 47.0
|
||||
margin_right = 66.0
|
||||
margin_bottom = 20.0
|
||||
text = "S"
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 24.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 44.0
|
||||
|
||||
[node name="Button4" type="Button" parent="VBoxContainer/HBoxContainer2"]
|
||||
margin_right = 19.0
|
||||
margin_bottom = 20.0
|
||||
text = "x"
|
||||
|
||||
[node name="Button5" type="Button" parent="VBoxContainer/HBoxContainer2"]
|
||||
margin_left = 23.0
|
||||
margin_right = 42.0
|
||||
margin_bottom = 20.0
|
||||
text = "y"
|
||||
|
||||
[node name="Button6" type="Button" parent="VBoxContainer/HBoxContainer2"]
|
||||
margin_left = 46.0
|
||||
margin_right = 65.0
|
||||
margin_bottom = 20.0
|
||||
text = "z"
|
@ -7,6 +7,8 @@ var plugin
|
||||
|
||||
var vertices : PoolVector3Array
|
||||
var indices : PoolIntArray
|
||||
var selected_indices : PoolIntArray
|
||||
var selected_vertices : PoolVector3Array
|
||||
|
||||
func set_handle(index: int, camera: Camera, point: Vector2):
|
||||
pass
|
||||
@ -45,16 +47,16 @@ func redraw():
|
||||
lines.append(vertices[i + 2])
|
||||
lines.append(vertices[i])
|
||||
|
||||
|
||||
|
||||
add_lines(lines, material, false)
|
||||
|
||||
add_handles(selected_vertices, handles_material)
|
||||
|
||||
func forward_spatial_gui_input(index, camera, event):
|
||||
if event is InputEventMouseButton:
|
||||
var gt : Transform = get_spatial_node().global_transform
|
||||
var ray_from : Vector3 = camera.global_transform.origin
|
||||
var gpoint : Vector2 = event.get_position()
|
||||
var grab_threshold : float = 4
|
||||
var grab_threshold : float = 8
|
||||
# var grab_threshold : float = 4 * EDSCALE;
|
||||
|
||||
if event.get_button_index() == BUTTON_LEFT:
|
||||
@ -71,23 +73,29 @@ func forward_spatial_gui_input(index, camera, event):
|
||||
|
||||
var vertices_size : int = vertices.size()
|
||||
for i in range(vertices_size):
|
||||
var joint_pos_3d : Vector3 = gt.xform(vertices[i])
|
||||
var joint_pos_2d : Vector2 = camera.unproject_position(joint_pos_3d)
|
||||
var dist_3d : float = ray_from.distance_to(joint_pos_3d)
|
||||
var dist_2d : float = gpoint.distance_to(joint_pos_2d)
|
||||
var vert_pos_3d : Vector3 = gt.xform(vertices[i])
|
||||
var vert_pos_2d : Vector2 = camera.unproject_position(vert_pos_3d)
|
||||
var dist_3d : float = ray_from.distance_to(vert_pos_3d)
|
||||
var dist_2d : float = gpoint.distance_to(vert_pos_2d)
|
||||
|
||||
if (dist_2d < grab_threshold && dist_3d < closest_dist):
|
||||
closest_dist = dist_3d;
|
||||
closest_idx = i;
|
||||
|
||||
if (closest_idx >= 0):
|
||||
print("f")
|
||||
else:
|
||||
print("nf")
|
||||
selected_indices.append(closest_idx)
|
||||
selected_vertices.append(vertices[closest_idx])
|
||||
|
||||
redraw()
|
||||
else:
|
||||
selected_indices.resize(0)
|
||||
selected_vertices.resize(0)
|
||||
|
||||
redraw()
|
||||
return false
|
||||
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_PREDELETE:
|
||||
plugin.unregister_gizmo(self)
|
||||
if plugin:
|
||||
plugin.unregister_gizmo(self)
|
||||
|
@ -2,20 +2,67 @@ tool
|
||||
extends EditorPlugin
|
||||
|
||||
const MdiGizmoPlugin = preload("res://addons/mesh_data_resource_editor/MDIGizmoPlugin.gd")
|
||||
const MDIEdGui = preload("res://addons/mesh_data_resource_editor/MDIEd.tscn")
|
||||
|
||||
var gizmo_plugin = MdiGizmoPlugin.new()
|
||||
var mdi_ed_gui : Control
|
||||
|
||||
var active_gizmos : Array = []
|
||||
var active_gizmos : Array
|
||||
|
||||
func _enter_tree():
|
||||
print("_enter_tree")
|
||||
|
||||
gizmo_plugin = MdiGizmoPlugin.new()
|
||||
mdi_ed_gui = MDIEdGui.instance()
|
||||
active_gizmos = []
|
||||
|
||||
gizmo_plugin.plugin = self
|
||||
|
||||
add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui)
|
||||
mdi_ed_gui.hide()
|
||||
|
||||
add_spatial_gizmo_plugin(gizmo_plugin)
|
||||
|
||||
set_input_event_forwarding_always_enabled()
|
||||
|
||||
func _exit_tree():
|
||||
print("_exit_tree")
|
||||
|
||||
remove_spatial_gizmo_plugin(gizmo_plugin)
|
||||
#remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui)
|
||||
mdi_ed_gui.queue_free()
|
||||
pass
|
||||
|
||||
#func enable_plugin():
|
||||
# print("enable_plugin")
|
||||
# pass
|
||||
#
|
||||
#func disable_plugin():
|
||||
# print("disable_plugin")
|
||||
# remove_spatial_gizmo_plugin(gizmo_plugin)
|
||||
# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui)
|
||||
# mdi_ed_gui.queue_free()
|
||||
|
||||
func handles(object):
|
||||
print("disable_plugin")
|
||||
|
||||
if object is MeshDataInstance:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func make_visible(visible):
|
||||
print("make_visible")
|
||||
|
||||
if visible:
|
||||
mdi_ed_gui.show()
|
||||
else:
|
||||
#mdi_ed_gui.hide()
|
||||
#figure out how to hide it when something else gets selected, don't hide on unselect
|
||||
pass
|
||||
|
||||
func get_plugin_name():
|
||||
return "mesh_data_resource_editor"
|
||||
|
||||
#func forward_spatial_gui_input(camera, event):
|
||||
# return forward_spatial_gui_input(0, camera, event)
|
||||
@ -29,9 +76,16 @@ func unregister_gizmo(gizmo):
|
||||
active_gizmos.remove(i)
|
||||
return
|
||||
|
||||
func forward_spatial_gui_input(index, camera, event):
|
||||
func forward_spatial_gui_input(camera, event):
|
||||
for g in active_gizmos:
|
||||
if g.forward_spatial_gui_input(index, camera, event):
|
||||
if g.forward_spatial_gui_input(0, camera, event):
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
#func forward_spatial_gui_input(index, camera, event):
|
||||
# for g in active_gizmos:
|
||||
# if g.forward_spatial_gui_input(index, camera, event):
|
||||
# return true
|
||||
#
|
||||
# return false
|
||||
|
Loading…
Reference in New Issue
Block a user