Fix uv island editing.

This commit is contained in:
Relintai 2022-04-14 12:14:59 +02:00
parent cd45c37881
commit 7f2cb4da8e

View File

@ -63,7 +63,7 @@ void MDRUVRectViewNode::mirror_horizontal() {
int index = r[ii]; int index = r[ii];
bool found = false; bool found = false;
PoolIntArray::Read pr = _indices.read(); PoolIntArray::Read pr = pia.read();
for (int i = 0; i < pia.size(); ++i) { for (int i = 0; i < pia.size(); ++i) {
if (pr[i] == index) { if (pr[i] == index) {
@ -85,6 +85,8 @@ void MDRUVRectViewNode::mirror_horizontal() {
_uvs.set(index, uv); _uvs.set(index, uv);
} }
r.release();
apply_uv(); apply_uv();
update(); update();
} }
@ -97,7 +99,7 @@ void MDRUVRectViewNode::mirror_vertical() {
int index = r[ii]; int index = r[ii];
bool found = false; bool found = false;
PoolIntArray::Read pr = _indices.read(); PoolIntArray::Read pr = pia.read();
for (int i = 0; i < pia.size(); ++i) { for (int i = 0; i < pia.size(); ++i) {
if (pr[i] == index) { if (pr[i] == index) {
@ -119,6 +121,8 @@ void MDRUVRectViewNode::mirror_vertical() {
_uvs.set(index, uv); _uvs.set(index, uv);
} }
r.release();
apply_uv(); apply_uv();
update(); update();
} }
@ -133,7 +137,7 @@ void MDRUVRectViewNode::rotate_uvs(float amount) {
int index = r[ii]; int index = r[ii];
bool found = false; bool found = false;
PoolIntArray::Read pr = _indices.read(); PoolIntArray::Read pr = pia.read();
for (int i = 0; i < pia.size(); ++i) { for (int i = 0; i < pia.size(); ++i) {
if (pr[i] == index) { if (pr[i] == index) {
@ -155,6 +159,8 @@ void MDRUVRectViewNode::rotate_uvs(float amount) {
_uvs.set(index, uv); _uvs.set(index, uv);
} }
r.release();
re_normalize_uvs(); re_normalize_uvs();
apply_uv(); apply_uv();
update(); update();
@ -260,7 +266,7 @@ void MDRUVRectViewNode::re_normalize_uvs() {
uv.y -= vmin.y; uv.y -= vmin.y;
uv.y /= ymm; uv.y /= ymm;
_uvs[i] = uv; _uvs.set(i, uv);
} }
} }
void MDRUVRectViewNode::normalize_uvs() { void MDRUVRectViewNode::normalize_uvs() {
@ -284,7 +290,7 @@ void MDRUVRectViewNode::normalize_uvs() {
uv.y -= _uv_min.y; uv.y -= _uv_min.y;
uv.y /= ymm; uv.y /= ymm;
_uvs[i] = uv; _uvs.set(i, uv);
} }
} }
void MDRUVRectViewNode::apply_uv() { void MDRUVRectViewNode::apply_uv() {
@ -312,14 +318,14 @@ void MDRUVRectViewNode::apply_uv() {
PoolVector2Array uvs = arrays[ArrayMesh::ARRAY_TEX_UV]; PoolVector2Array uvs = arrays[ArrayMesh::ARRAY_TEX_UV];
for (int i = 0; i < _uvs.size(); ++i) { for (int i = 0; i < _indices.size(); ++i) {
int index = _indices[i]; int index = _indices[i];
Vector2 uv = _uvs[index]; Vector2 uv = _uvs[index];
uv = uv * rect.size + rect.position; uv = uv * rect.size + rect.position;
uvs[index] = uv; uvs.set(index, uv);
} }
_uv_min = rect.position; _uv_min = rect.position;