diff --git a/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd b/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd index 888128d1..02990d3a 100644 --- a/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd +++ b/game/addons/mesh_data_resource_editor/MDIGizmoPlugin.gd @@ -21,8 +21,6 @@ func create_gizmo(spatial): gizmo.set_spatial_node(spatial) gizmo.setup() - - #gizmo.plugin = plugin plugin.register_gizmo(gizmo) return gizmo diff --git a/game/addons/mesh_data_resource_editor/MIDGizmo.gd b/game/addons/mesh_data_resource_editor/MIDGizmo.gd index 1ef2b185..6dab5fa3 100644 --- a/game/addons/mesh_data_resource_editor/MIDGizmo.gd +++ b/game/addons/mesh_data_resource_editor/MIDGizmo.gd @@ -26,7 +26,6 @@ enum SelectionMode { var gizmo_size = 3.0 var vertices : PoolVector3Array -var indices : PoolIntArray var handle_points : PoolVector3Array var handle_to_vertex_map : Array @@ -75,8 +74,9 @@ func set_handle(index: int, camera: Camera, point: Vector2): add_to_all_selected(ofs) - redraw() + recalculate_handle_points() apply() + redraw() elif edit_mode == EditMode.EDIT_MODE_SCALE: var r : float = 1.0 + ((relative.x + relative.y) * 0.05) @@ -95,8 +95,9 @@ func set_handle(index: int, camera: Camera, point: Vector2): mul_all_selected_with_basis(b) - redraw() + recalculate_handle_points() apply() + redraw() elif edit_mode == EditMode.EDIT_MODE_ROTATE: print("MDR Editor: ROTATE NYI") @@ -141,7 +142,6 @@ func apply() -> void: arrs[ArrayMesh.ARRAY_VERTEX] = vertices _mdr.array = arrs - func forward_spatial_gui_input(index, camera, event): if event is InputEventMouseButton: var gt : Transform = get_spatial_node().global_transform @@ -281,6 +281,25 @@ func _notification(what): if get_plugin(): get_plugin().unregister_gizmo(self) +#todo if selection type changed recalc handles aswell + #add method recalc handles -> check for type +func recalculate_handle_points() -> void: + if !_mdr: + handle_points.resize(0) + handle_to_vertex_map.resize(0) + + var merged_arrays : Array = MeshUtils.merge_mesh_array(_mdr.array) + handle_points = merged_arrays[ArrayMesh.ARRAY_VERTEX] + + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: + handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(_mdr.array, handle_points) + elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: + #todo + handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(_mdr.array, handle_points) + elif selection_mode == SelectionMode.SELECTION_MODE_FACE: + #todo + handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(_mdr.array, handle_points) + func on_mesh_data_resource_changed(mdr : MeshDataResource) -> void: _mdr = mdr @@ -289,9 +308,5 @@ func on_mesh_data_resource_changed(mdr : MeshDataResource) -> void: else: vertices.resize(0) - #recalc handle points - - #if selection type changed recalc handles aswell - #add method recalc handles -> check for type - + recalculate_handle_points() redraw() diff --git a/game/addons/mesh_data_resource_editor/utilities/mesh_decompose.gd b/game/addons/mesh_data_resource_editor/utilities/mesh_decompose.gd index 794b1629..c2f3085f 100644 --- a/game/addons/mesh_data_resource_editor/utilities/mesh_decompose.gd +++ b/game/addons/mesh_data_resource_editor/utilities/mesh_decompose.gd @@ -5,10 +5,32 @@ extends Object static func get_handle_vertex_to_vertex_map(arrays : Array, handle_points : PoolVector3Array) -> Array: var handle_to_vertex_map : Array + handle_to_vertex_map.resize(handle_points.size()) - #foreach handle points - #get all equal approx vertex and put it into the map + if handle_points.size() == 0: + return handle_to_vertex_map + if arrays.size() != ArrayMesh.ARRAY_MAX || arrays[ArrayMesh.ARRAY_INDEX] == null: + return handle_to_vertex_map + + var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX] + + if vertices.size() == 0: + return handle_to_vertex_map + + for i in range(handle_points.size()): + var hv : Vector3 = handle_points[i] + var iarr : PoolIntArray = PoolIntArray() + + #find all verts that have the same position as the handle + for j in range(vertices.size()): + var vn : Vector3 = vertices[j] + + if is_equal_approx(hv.x, vn.x) && is_equal_approx(hv.y, vn.y) && is_equal_approx(hv.z, vn.z): + iarr.append(j) + + handle_to_vertex_map[i] = iarr + return handle_to_vertex_map static func get_handle_edge_to_vertex_map() -> Array: