Implemented horizontal and vertical mirroring for the uv editor.

This commit is contained in:
Relintai 2022-02-13 12:57:18 +01:00
parent 8ae0b5b236
commit 05f1c2c365
2 changed files with 55 additions and 4 deletions

View File

@ -63,19 +63,23 @@ func _enter_tree():
connect("visibility_changed", self, "on_visibility_changed")
func on_mirror_horizontal_button_pressed() -> void:
pass
if selected_rect && is_instance_valid(selected_rect):
selected_rect.mirror_horizontal()
func on_mirror_vertical_button_pressed() -> void:
pass
if selected_rect && is_instance_valid(selected_rect):
selected_rect.mirror_vertical()
func on_rotate_left_button_button_pressed() -> void:
pass
if selected_rect && is_instance_valid(selected_rect):
selected_rect.rotate_uvs(rotation_amount)
func on_rotate_amount_spinbox_changed(val : float) -> void:
rotation_amount = val
func on_rotate_right_button_button_pressed() -> void:
pass
if selected_rect && is_instance_valid(selected_rect):
selected_rect.rotate_uvs(-rotation_amount)
func set_plugin(plugin : EditorPlugin) -> void:
_plugin = plugin

View File

@ -52,6 +52,53 @@ func _draw():
draw_line(_uvs[_indices[i + 1]] * get_size(), _uvs[_indices[i + 2]] * get_size(), c, 1, false)
draw_line(_uvs[_indices[i + 2]] * get_size(), _uvs[_indices[i]] * get_size(), c, 1, false)
func mirror_horizontal() -> void:
var pia : PoolIntArray = PoolIntArray()
for index in _indices:
var found : bool = false
for i in pia:
if i == index:
found = true
break
if found:
continue
pia.append(index)
var uv : Vector2 = _uvs[index]
uv.x = 1.0 - uv.x
_uvs.set(index, uv)
apply_uv()
update()
func mirror_vertical() -> void:
var pia : PoolIntArray = PoolIntArray()
for index in _indices:
var found : bool = false
for i in pia:
if i == index:
found = true
break
if found:
continue
pia.append(index)
var uv : Vector2 = _uvs[index]
uv.y = 1.0 - uv.y
_uvs.set(index, uv)
apply_uv()
update()
func rotate_uvs(amount : float) -> void:
pass
func refresh() -> void:
if !_mdr:
return