From 25c71e2c14687045b1d3bbd1f3b146429add5514 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 18 Jan 2022 21:41:39 +0100 Subject: [PATCH] Moved some of the new helper methods to the mesh utils script. --- .../mesh_data_resource_editor/MIDGizmo.gd | 58 ++----------------- .../utilities/mdred_mesh_utils.gd | 51 ++++++++++++++++ 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/game/addons/mesh_data_resource_editor/MIDGizmo.gd b/game/addons/mesh_data_resource_editor/MIDGizmo.gd index 7b6f6a0f..f6a5b24d 100644 --- a/game/addons/mesh_data_resource_editor/MIDGizmo.gd +++ b/game/addons/mesh_data_resource_editor/MIDGizmo.gd @@ -947,56 +947,6 @@ func get_all_index_pairs_for_edge(edge : int) -> PoolIntArray: return ret -func order_seam_indices(arr : PoolIntArray) -> PoolIntArray: - var ret : PoolIntArray = PoolIntArray() - - if arr.size() == 0: - return ret - - for i in range(0, arr.size(), 2): - var index0 : int = arr[i] - var index1 : int = arr[i + 1] - - if index0 > index1: - var t : int = index1 - index1 = index0 - index0 = t - - ret.push_back(index0) - ret.push_back(index1) - - return ret - -func has_seam(index0 : int, index1 : int) -> bool: - var seams : PoolIntArray = _mdr.seams - - for i in range(0, seams.size(), 2): - if seams[i] == index0 && seams[i + 1] == index1: - return true - - return false - -func add_seam(index0 : int, index1 : int) -> void: - if has_seam(index0, index1): - return - - var seams : PoolIntArray = _mdr.seams - seams.push_back(index0) - seams.push_back(index1) - _mdr.seams = seams - -func remove_seam(index0 : int, index1 : int) -> void: - if !has_seam(index0, index1): - return - - var seams : PoolIntArray = _mdr.seams - - for i in range(0, seams.size(), 2): - if seams[i] == index0 && seams[i + 1] == index1: - seams.remove(i) - seams.remove(i) - _mdr.seams = seams - return func mark_seam(): if !_mdr: @@ -1011,12 +961,12 @@ func mark_seam(): _mdr.disconnect("changed", self, "on_mdr_changed") for se in _selected_points: - var eis : PoolIntArray = order_seam_indices(get_first_index_pair_for_edge(se)) + var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_first_index_pair_for_edge(se)) if eis.size() == 0: continue - add_seam(eis[0], eis[1]) + MDRMeshUtils.add_seam(_mdr, eis[0], eis[1]) _mdr.connect("changed", self, "on_mdr_changed") on_mdr_changed() @@ -1036,12 +986,12 @@ func unmark_seam(): _mdr.disconnect("changed", self, "on_mdr_changed") for se in _selected_points: - var eis : PoolIntArray = order_seam_indices(get_all_index_pairs_for_edge(se)) + var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_all_index_pairs_for_edge(se)) if eis.size() == 0: continue - remove_seam(eis[0], eis[1]) + MDRMeshUtils.remove_seam(_mdr, eis[0], eis[1]) _mdr.connect("changed", self, "on_mdr_changed") on_mdr_changed() diff --git a/game/addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd b/game/addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd index c9a59e0c..c4c0ef5b 100644 --- a/game/addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd +++ b/game/addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd @@ -652,3 +652,54 @@ static func generate_tangents(mdr : MeshDataResource) -> void: st.generate_tangents() mdr.array = st.commit_to_arrays() + +static func order_seam_indices(arr : PoolIntArray) -> PoolIntArray: + var ret : PoolIntArray = PoolIntArray() + + if arr.size() == 0: + return ret + + for i in range(0, arr.size(), 2): + var index0 : int = arr[i] + var index1 : int = arr[i + 1] + + if index0 > index1: + var t : int = index1 + index1 = index0 + index0 = t + + ret.push_back(index0) + ret.push_back(index1) + + return ret + +static func has_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> bool: + var seams : PoolIntArray = mdr.seams + + for i in range(0, seams.size(), 2): + if seams[i] == index0 && seams[i + 1] == index1: + return true + + return false + +static func add_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> void: + if has_seam(mdr, index0, index1): + return + + var seams : PoolIntArray = mdr.seams + seams.push_back(index0) + seams.push_back(index1) + mdr.seams = seams + +static func remove_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> void: + if !has_seam(mdr, index0, index1): + return + + var seams : PoolIntArray = mdr.seams + + for i in range(0, seams.size(), 2): + if seams[i] == index0 && seams[i + 1] == index1: + seams.remove(i) + seams.remove(i) + mdr.seams = seams + return