2021-02-08 08:24:40 +01:00
|
|
|
tool
|
|
|
|
extends EditorPlugin
|
|
|
|
|
2022-01-14 13:17:31 +01:00
|
|
|
const MDRMeshUtils = preload("res://addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd")
|
2021-12-29 00:00:28 +01:00
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
const MdiGizmoPlugin = preload("res://addons/mesh_data_resource_editor/MDIGizmoPlugin.gd")
|
2021-03-02 13:03:02 +01:00
|
|
|
const MDIEdGui = preload("res://addons/mesh_data_resource_editor/MDIEd.tscn")
|
2021-02-08 08:24:40 +01:00
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
var gizmo_plugin = MdiGizmoPlugin.new()
|
2021-03-02 13:03:02 +01:00
|
|
|
var mdi_ed_gui : Control
|
2021-02-08 08:24:40 +01:00
|
|
|
|
2021-03-02 13:03:02 +01:00
|
|
|
var active_gizmos : Array
|
2021-02-28 00:18:38 +01:00
|
|
|
|
2021-09-13 18:47:56 +02:00
|
|
|
var current_mesh_data_instance : MeshDataInstance = null
|
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
func _enter_tree():
|
2021-09-13 12:32:33 +02:00
|
|
|
#print("_enter_tree")
|
2021-03-02 13:03:02 +01:00
|
|
|
|
|
|
|
gizmo_plugin = MdiGizmoPlugin.new()
|
|
|
|
mdi_ed_gui = MDIEdGui.instance()
|
2021-03-02 21:41:24 +01:00
|
|
|
mdi_ed_gui.plugin = self
|
2021-03-02 13:03:02 +01:00
|
|
|
active_gizmos = []
|
|
|
|
|
2021-02-28 00:18:38 +01:00
|
|
|
gizmo_plugin.plugin = self
|
|
|
|
|
2021-03-02 13:03:02 +01:00
|
|
|
add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui)
|
|
|
|
mdi_ed_gui.hide()
|
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
add_spatial_gizmo_plugin(gizmo_plugin)
|
2021-02-28 00:18:38 +01:00
|
|
|
|
|
|
|
set_input_event_forwarding_always_enabled()
|
2021-02-08 08:24:40 +01:00
|
|
|
|
|
|
|
func _exit_tree():
|
2021-09-13 12:32:33 +02:00
|
|
|
#print("_exit_tree")
|
2021-03-02 13:03:02 +01:00
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
remove_spatial_gizmo_plugin(gizmo_plugin)
|
2021-03-02 13:03:02 +01:00
|
|
|
#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):
|
2021-09-13 12:32:33 +02:00
|
|
|
#print("disable_plugin")
|
2021-03-02 13:03:02 +01:00
|
|
|
|
|
|
|
if object is MeshDataInstance:
|
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
2021-09-13 12:32:33 +02:00
|
|
|
|
|
|
|
func edit(object):
|
|
|
|
var mdi : MeshDataInstance = object as MeshDataInstance
|
2021-03-02 13:03:02 +01:00
|
|
|
|
2021-09-13 18:47:56 +02:00
|
|
|
current_mesh_data_instance = mdi
|
|
|
|
|
2021-09-13 12:32:33 +02:00
|
|
|
if mdi:
|
|
|
|
mdi_ed_gui.set_mesh_data_resource(mdi.mesh_data)
|
2022-01-20 00:21:23 +01:00
|
|
|
mdi_ed_gui.set_mesh_data_instance(mdi)
|
2021-09-13 12:32:33 +02:00
|
|
|
|
2021-03-02 13:03:02 +01:00
|
|
|
func make_visible(visible):
|
2021-09-13 12:32:33 +02:00
|
|
|
#print("make_visible")
|
2021-03-02 13:03:02 +01:00
|
|
|
|
|
|
|
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
|
2021-09-13 12:32:33 +02:00
|
|
|
|
2021-03-02 13:03:02 +01:00
|
|
|
func get_plugin_name():
|
|
|
|
return "mesh_data_resource_editor"
|
2021-09-13 12:32:33 +02:00
|
|
|
|
2021-02-28 00:18:38 +01:00
|
|
|
|
|
|
|
#func forward_spatial_gui_input(camera, event):
|
|
|
|
# return forward_spatial_gui_input(0, camera, event)
|
|
|
|
|
|
|
|
func register_gizmo(gizmo):
|
|
|
|
active_gizmos.append(gizmo)
|
|
|
|
|
|
|
|
func unregister_gizmo(gizmo):
|
|
|
|
for i in range(active_gizmos.size()):
|
|
|
|
if active_gizmos[i] == gizmo:
|
|
|
|
active_gizmos.remove(i)
|
|
|
|
return
|
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_translate(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
for g in active_gizmos:
|
2021-03-24 19:09:02 +01:00
|
|
|
g.set_translate(on)
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_scale(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
for g in active_gizmos:
|
2021-03-24 19:09:02 +01:00
|
|
|
g.set_scale(on)
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_rotate(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
for g in active_gizmos:
|
2021-03-24 19:09:02 +01:00
|
|
|
g.set_rotate(on)
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_axis_x(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
for g in active_gizmos:
|
2021-03-24 19:09:02 +01:00
|
|
|
g.set_axis_x(on)
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_axis_y(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
for g in active_gizmos:
|
2021-03-24 19:09:02 +01:00
|
|
|
g.set_axis_y(on)
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_axis_z(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
for g in active_gizmos:
|
2021-03-24 19:09:02 +01:00
|
|
|
g.set_axis_z(on)
|
2021-09-13 18:47:56 +02:00
|
|
|
|
2021-12-31 08:18:56 +01:00
|
|
|
func set_selection_mode_vertex() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.set_selection_mode_vertex()
|
|
|
|
|
|
|
|
func set_selection_mode_edge() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.set_selection_mode_edge()
|
|
|
|
|
|
|
|
func set_selection_mode_face() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.set_selection_mode_face()
|
|
|
|
|
2021-12-29 00:00:28 +01:00
|
|
|
func get_mdr() -> MeshDataResource:
|
|
|
|
if current_mesh_data_instance:
|
|
|
|
return current_mesh_data_instance.mesh_data
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
2021-09-26 23:02:51 +02:00
|
|
|
|
2021-09-26 20:04:42 +02:00
|
|
|
#func forward_spatial_gui_input(camera, event):
|
2021-03-02 13:03:02 +01:00
|
|
|
# for g in active_gizmos:
|
2021-09-26 20:04:42 +02:00
|
|
|
# if g.forward_spatial_gui_input(0, camera, event):
|
2021-03-02 13:03:02 +01:00
|
|
|
# return true
|
|
|
|
#
|
|
|
|
# return false
|
2021-09-26 20:04:42 +02:00
|
|
|
|
|
|
|
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
|
2021-12-29 00:00:28 +01:00
|
|
|
|
|
|
|
func add_box() -> void:
|
|
|
|
var mdr : MeshDataResource = get_mdr()
|
|
|
|
|
|
|
|
if mdr:
|
2022-01-14 13:17:31 +01:00
|
|
|
MDRMeshUtils.add_box(mdr)
|
2022-01-03 14:45:40 +01:00
|
|
|
|
|
|
|
func add_triangle() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.add_triangle()
|
|
|
|
|
|
|
|
func add_quad() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.add_quad()
|
2022-01-03 17:33:34 +01:00
|
|
|
|
2022-01-14 15:24:59 +01:00
|
|
|
func add_triangle_at() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.add_triangle_at()
|
|
|
|
|
|
|
|
func add_quad_at() -> void:
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.add_quad_at()
|
|
|
|
|
2022-01-03 17:33:34 +01:00
|
|
|
func split():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.split()
|
|
|
|
|
|
|
|
func connect_action():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.connect_action()
|
|
|
|
|
|
|
|
func disconnect_action():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.disconnect_action()
|
2022-01-15 13:44:14 +01:00
|
|
|
|
|
|
|
func create_face():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.create_face()
|
2022-01-15 15:18:14 +01:00
|
|
|
|
|
|
|
func delete_selected():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.delete_selected()
|
2022-01-15 15:53:08 +01:00
|
|
|
|
|
|
|
func generate_normals():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.generate_normals()
|
|
|
|
|
|
|
|
func remove_doubles():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.remove_doubles()
|
|
|
|
|
|
|
|
func merge_optimize():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.merge_optimize()
|
|
|
|
|
|
|
|
func generate_tangents():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.generate_tangents()
|
2022-01-15 16:13:09 +01:00
|
|
|
|
|
|
|
func onnect_to_first_selected():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.onnect_to_first_selected()
|
|
|
|
|
|
|
|
func connect_to_avg():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.connect_to_avg()
|
|
|
|
|
|
|
|
func connect_to_last_selected():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.connect_to_last_selected()
|
2022-01-15 16:24:34 +01:00
|
|
|
|
|
|
|
func mark_seam():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.mark_seam()
|
|
|
|
|
|
|
|
func unmark_seam():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.unmark_seam()
|
2022-01-18 22:24:22 +01:00
|
|
|
|
|
|
|
func apply_seam():
|
|
|
|
for g in active_gizmos:
|
|
|
|
g.apply_seam()
|
2022-01-19 00:17:39 +01:00
|
|
|
|
|
|
|
func uv_unwrap() -> void:
|
|
|
|
for g in active_gizmos:
|
2022-01-19 01:01:32 +01:00
|
|
|
g.uv_unwrap()
|
2022-01-19 00:17:39 +01:00
|
|
|
|