mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Added undo redo support for uv_unwrap, apply_seam, mark_seam, and unmark_seam.
This commit is contained in:
parent
62fc405cc5
commit
6b56563056
@ -20,6 +20,7 @@ func create_gizmo(spatial):
|
|||||||
if spatial is MeshDataInstance:
|
if spatial is MeshDataInstance:
|
||||||
var gizmo = MDIGizmo.new()
|
var gizmo = MDIGizmo.new()
|
||||||
|
|
||||||
|
gizmo.set_editor_plugin(plugin)
|
||||||
gizmo.set_spatial_node(spatial)
|
gizmo.set_spatial_node(spatial)
|
||||||
gizmo.setup()
|
gizmo.setup()
|
||||||
plugin.register_gizmo(gizmo)
|
plugin.register_gizmo(gizmo)
|
||||||
|
@ -43,6 +43,9 @@ var _selected_points : PoolIntArray
|
|||||||
|
|
||||||
var _mesh_outline_generator
|
var _mesh_outline_generator
|
||||||
|
|
||||||
|
var _editor_plugin : EditorPlugin = null
|
||||||
|
var _undo_redo : UndoRedo = null
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
_mesh_outline_generator = MeshOutline.new()
|
_mesh_outline_generator = MeshOutline.new()
|
||||||
|
|
||||||
@ -50,6 +53,11 @@ func setup() -> void:
|
|||||||
get_spatial_node().connect("mesh_data_resource_changed", self, "on_mesh_data_resource_changed")
|
get_spatial_node().connect("mesh_data_resource_changed", self, "on_mesh_data_resource_changed")
|
||||||
on_mesh_data_resource_changed(get_spatial_node().mesh_data)
|
on_mesh_data_resource_changed(get_spatial_node().mesh_data)
|
||||||
|
|
||||||
|
func set_editor_plugin(editor_plugin : EditorPlugin) -> void:
|
||||||
|
_editor_plugin = editor_plugin
|
||||||
|
|
||||||
|
_undo_redo = _editor_plugin.get_undo_redo()
|
||||||
|
|
||||||
func set_handle(index: int, camera: Camera, point: Vector2):
|
func set_handle(index: int, camera: Camera, point: Vector2):
|
||||||
var relative : Vector2 = point - previous_point
|
var relative : Vector2 = point - previous_point
|
||||||
|
|
||||||
@ -997,6 +1005,8 @@ func mark_seam():
|
|||||||
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
||||||
disable_change_event()
|
disable_change_event()
|
||||||
|
|
||||||
|
var prev_seams : PoolIntArray = copy_pool_int_array(_mdr.seams)
|
||||||
|
|
||||||
for se in _selected_points:
|
for se in _selected_points:
|
||||||
var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_first_index_pair_for_edge(se))
|
var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_first_index_pair_for_edge(se))
|
||||||
|
|
||||||
@ -1005,10 +1015,15 @@ func mark_seam():
|
|||||||
|
|
||||||
MDRMeshUtils.add_seam(_mdr, eis[0], eis[1])
|
MDRMeshUtils.add_seam(_mdr, eis[0], eis[1])
|
||||||
|
|
||||||
|
_undo_redo.create_action("mark_seam")
|
||||||
|
_undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(_mdr.seams))
|
||||||
|
_undo_redo.add_undo_method(self, "set_seam", _mdr, prev_seams)
|
||||||
|
_undo_redo.commit_action()
|
||||||
|
|
||||||
enable_change_event()
|
enable_change_event()
|
||||||
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func unmark_seam():
|
func unmark_seam():
|
||||||
if !_mdr:
|
if !_mdr:
|
||||||
return
|
return
|
||||||
@ -1021,6 +1036,8 @@ func unmark_seam():
|
|||||||
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
||||||
disable_change_event()
|
disable_change_event()
|
||||||
|
|
||||||
|
var prev_seams : PoolIntArray = copy_pool_int_array(_mdr.seams)
|
||||||
|
|
||||||
for se in _selected_points:
|
for se in _selected_points:
|
||||||
var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_all_index_pairs_for_edge(se))
|
var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_all_index_pairs_for_edge(se))
|
||||||
|
|
||||||
@ -1029,20 +1046,29 @@ func unmark_seam():
|
|||||||
|
|
||||||
MDRMeshUtils.remove_seam(_mdr, eis[0], eis[1])
|
MDRMeshUtils.remove_seam(_mdr, eis[0], eis[1])
|
||||||
|
|
||||||
|
_undo_redo.create_action("mark_seam")
|
||||||
|
_undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(_mdr.seams))
|
||||||
|
_undo_redo.add_undo_method(self, "set_seam", _mdr, prev_seams)
|
||||||
|
_undo_redo.commit_action()
|
||||||
|
|
||||||
enable_change_event()
|
enable_change_event()
|
||||||
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func set_seam(mdr : MeshDataResource, arr : PoolIntArray) -> void:
|
||||||
|
mdr.seams = arr
|
||||||
|
|
||||||
func apply_seam():
|
func apply_seam():
|
||||||
if !_mdr:
|
if !_mdr:
|
||||||
return
|
return
|
||||||
|
|
||||||
_mdr.disconnect("changed", self, "on_mdr_changed")
|
disable_change_event()
|
||||||
|
|
||||||
|
var orig_arr : Array = copy_arrays(_mdr.array)
|
||||||
MDRMeshUtils.apply_seam(_mdr)
|
MDRMeshUtils.apply_seam(_mdr)
|
||||||
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "apply_seam")
|
||||||
|
|
||||||
_mdr.connect("changed", self, "on_mdr_changed")
|
enable_change_event()
|
||||||
on_mdr_changed()
|
|
||||||
|
|
||||||
func uv_unwrap() -> void:
|
func uv_unwrap() -> void:
|
||||||
if !_mdr:
|
if !_mdr:
|
||||||
@ -1052,12 +1078,43 @@ func uv_unwrap() -> void:
|
|||||||
|
|
||||||
if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0:
|
if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
disable_change_event()
|
||||||
|
|
||||||
var uvs : PoolVector2Array = MeshUtils.uv_unwrap(mdr_arr)
|
var uvs : PoolVector2Array = MeshUtils.uv_unwrap(mdr_arr)
|
||||||
|
|
||||||
if uvs.size() != mdr_arr[ArrayMesh.ARRAY_VERTEX].size():
|
if uvs.size() != mdr_arr[ArrayMesh.ARRAY_VERTEX].size():
|
||||||
print("Error: Could not unwrap mesh!")
|
print("Error: Could not unwrap mesh!")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
var orig_arr : Array = copy_arrays(mdr_arr)
|
||||||
|
|
||||||
mdr_arr[ArrayMesh.ARRAY_TEX_UV] = uvs
|
mdr_arr[ArrayMesh.ARRAY_TEX_UV] = uvs
|
||||||
_mdr.set_array(mdr_arr)
|
|
||||||
|
add_mesh_change_undo_redo(orig_arr, mdr_arr, "uv_unwrap")
|
||||||
|
enable_change_event()
|
||||||
|
|
||||||
|
func add_mesh_change_undo_redo(orig_arr : Array, new_arr : Array, action_name : String) -> void:
|
||||||
|
_undo_redo.create_action(action_name)
|
||||||
|
var nac : Array = copy_arrays(new_arr)
|
||||||
|
_undo_redo.add_do_method(self, "apply_mesh_change", _mdr, nac)
|
||||||
|
_undo_redo.add_undo_method(self, "apply_mesh_change", _mdr, orig_arr)
|
||||||
|
_undo_redo.commit_action()
|
||||||
|
|
||||||
|
func apply_mesh_change(mdr : MeshDataResource, arr : Array) -> void:
|
||||||
|
if !mdr:
|
||||||
|
return
|
||||||
|
|
||||||
|
mdr.array = copy_arrays(arr)
|
||||||
|
|
||||||
|
func copy_arrays(arr : Array) -> Array:
|
||||||
|
return arr.duplicate(true)
|
||||||
|
|
||||||
|
func copy_pool_int_array(pia : PoolIntArray) -> PoolIntArray:
|
||||||
|
var ret : PoolIntArray = PoolIntArray()
|
||||||
|
ret.resize(pia.size())
|
||||||
|
|
||||||
|
for i in range(pia.size()):
|
||||||
|
ret[i] = pia[i]
|
||||||
|
|
||||||
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user