From 7cdf7f2f610bd9098c1cc31abad337787d669afe Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 9 Feb 2021 01:40:13 +0100 Subject: [PATCH] Work on the mesh data resource editor plugin. --- .../MDIGizmoPlugin.gd | 21 ++++++++ .../mesh_data_resource_editor/MIDGizmo.gd | 52 +++++++++++++++++++ .../mesh_data_resource_editor/plugin.gd | 8 +-- game/project.godot | 2 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd create mode 100644 game/addons/mesh_data_resource_editor/MIDGizmo.gd diff --git a/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd b/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd new file mode 100644 index 00000000..be7c655a --- /dev/null +++ b/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd @@ -0,0 +1,21 @@ +tool +extends EditorSpatialGizmoPlugin + +const MDIGizmo = preload("res://addons/mesh_data_resource_editor/MIDGizmo.gd") + +func _init(): + create_material("main", Color(1, 0, 0)) + create_handle_material("handles") + +func get_name(): + return "MDIGizmo" + +func get_priority(): + return 100 + +func create_gizmo(spatial): + if spatial is MeshDataInstance: + print("new gizmo") + return MDIGizmo.new() + else: + return null diff --git a/game/addons/mesh_data_resource_editor/MIDGizmo.gd b/game/addons/mesh_data_resource_editor/MIDGizmo.gd new file mode 100644 index 00000000..2a4a4e78 --- /dev/null +++ b/game/addons/mesh_data_resource_editor/MIDGizmo.gd @@ -0,0 +1,52 @@ +tool +extends EditorSpatialGizmo + +var gizmo_size = 3.0 + +func set_handle(index: int, camera: Camera, point: Vector2): + #print(index) + #print(point) + + + + pass + +func redraw(): + #print("MIDGizmo redraw") + + clear() + + var node : MeshDataInstance = get_spatial_node() + + if !node: + return + + var mdr : MeshDataResource = node.mesh_data + + if !mdr: + return + + var handles_material : SpatialMaterial = get_plugin().get_material("handles", self) + + var handles : PoolVector3Array = mdr.array[ArrayMesh.ARRAY_VERTEX] + add_handles(handles, handles_material) + + var material = get_plugin().get_material("main", self) + var lines : PoolVector3Array = PoolVector3Array() + var indices : PoolIntArray = mdr.array[ArrayMesh.ARRAY_INDEX] + + if indices.size() % 3 == 0: + for i in range(0, len(indices), 3): + lines.append(handles[i]) + lines.append(handles[i + 1]) + + lines.append(handles[i + 1]) + lines.append(handles[i + 2]) + + lines.append(handles[i + 2]) + lines.append(handles[i]) + + + + add_lines(lines, material, false) + diff --git a/game/addons/mesh_data_resource_editor/plugin.gd b/game/addons/mesh_data_resource_editor/plugin.gd index 49e712eb..c34ad77c 100644 --- a/game/addons/mesh_data_resource_editor/plugin.gd +++ b/game/addons/mesh_data_resource_editor/plugin.gd @@ -1,10 +1,12 @@ tool extends EditorPlugin +const MdiGizmoPlugin = preload("res://addons/mesh_data_resource_editor/MDIGizmoPlugin.gd") + +var gizmo_plugin = MdiGizmoPlugin.new() func _enter_tree(): - pass - + add_spatial_gizmo_plugin(gizmo_plugin) func _exit_tree(): - pass + remove_spatial_gizmo_plugin(gizmo_plugin) diff --git a/game/project.godot b/game/project.godot index 8ee29459..d137df10 100644 --- a/game/project.godot +++ b/game/project.godot @@ -311,7 +311,7 @@ window/size/ui_scale_touch=1.0 [editor_plugins] -enabled=PoolStringArray( "Godoxel", "gdpose", "mesh_data_resource_editor" ) +enabled=PoolStringArray( "Godoxel", "gdpose" ) [ess]