mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Normalize uvs in the rect view node. Also cleaned up draw a bit.
This commit is contained in:
parent
4484c0e0c9
commit
2d43cace5d
@ -14,6 +14,8 @@ var _mdr : MeshDataResource = null
|
||||
var _indices : PoolIntArray = PoolIntArray()
|
||||
var _uvs : PoolVector2Array = PoolVector2Array()
|
||||
var _base_rect : Rect2 = Rect2(0, 0, 100, 100)
|
||||
var _uv_min : Vector2 = Vector2()
|
||||
var _uv_max : Vector2 = Vector2()
|
||||
|
||||
var edited_resource_parent_size : Vector2 = Vector2()
|
||||
|
||||
@ -35,31 +37,13 @@ func _draw():
|
||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_border_color, false, _editor_rect_border_size)
|
||||
|
||||
if _mdr && _uvs.size() > 0:
|
||||
for i in range(0, len(_indices), 3):
|
||||
var c : Color = Color(1, 1, 1, 1)
|
||||
|
||||
if _uvs[_indices[i]].is_equal_approx(Vector2()) || _uvs[_indices[i + 1]].is_equal_approx(Vector2()):
|
||||
c = Color(1, 0, 0, 1)
|
||||
else:
|
||||
c = Color(1, 1, 1, 1)
|
||||
|
||||
for i in range(0, len(_indices), 3):
|
||||
draw_line(_uvs[_indices[i]] * get_size(), _uvs[_indices[i + 1]] * get_size(), c, 1, false)
|
||||
|
||||
if _uvs[_indices[i + 1]].is_equal_approx(Vector2()) || _uvs[_indices[i + 2]].is_equal_approx(Vector2()):
|
||||
c = Color(1, 0, 0, 1)
|
||||
else:
|
||||
c = Color(1, 1, 1, 1)
|
||||
|
||||
draw_line(_uvs[_indices[i + 1]] * get_size(), _uvs[_indices[i + 2]] * get_size(), c, 1, false)
|
||||
|
||||
if _uvs[_indices[i + 2]].is_equal_approx(Vector2()) || _uvs[_indices[i]].is_equal_approx(Vector2()):
|
||||
c = Color(1, 0, 0, 1)
|
||||
else:
|
||||
c = Color(1, 1, 1, 1)
|
||||
|
||||
draw_line(_uvs[_indices[i + 2]] * get_size(), _uvs[_indices[i]] * get_size(), c, 1, false)
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
if !_mdr:
|
||||
return
|
||||
@ -95,7 +79,8 @@ func set_edited_resource(mdr : MeshDataResource, indices : PoolIntArray):
|
||||
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
||||
return
|
||||
|
||||
_uvs = arrays[ArrayMesh.ARRAY_TEX_UV]
|
||||
# Make sure it gets copied
|
||||
_uvs.append_array(arrays[ArrayMesh.ARRAY_TEX_UV])
|
||||
|
||||
set_up_base_rect()
|
||||
|
||||
@ -131,6 +116,32 @@ func set_up_base_rect() -> void:
|
||||
_base_rect.position *= edited_resource_parent_size
|
||||
_base_rect.size *= edited_resource_parent_size
|
||||
|
||||
_uv_min = vmin
|
||||
_uv_max = vmax
|
||||
|
||||
normalize_uvs()
|
||||
|
||||
func normalize_uvs() -> void:
|
||||
var xmm : float = _uv_max.x - _uv_min.x
|
||||
var ymm : float = _uv_max.x - _uv_min.x
|
||||
|
||||
if xmm == 0:
|
||||
xmm = 0.0000001
|
||||
|
||||
if ymm == 0:
|
||||
ymm = 0.0000001
|
||||
|
||||
for i in range(_uvs.size()):
|
||||
var uv : Vector2 = _uvs[i]
|
||||
|
||||
uv.x -= _uv_min.x
|
||||
uv.x /= xmm
|
||||
|
||||
uv.y -= _uv_min.y
|
||||
uv.y /= ymm
|
||||
|
||||
_uvs[i] = uv
|
||||
|
||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
||||
func _notification(p_what : int) -> void:
|
||||
if (p_what == NOTIFICATION_MOUSE_EXIT):
|
||||
|
Loading…
Reference in New Issue
Block a user