Check arrays before generating Polygon2D AABBs
This commit is contained in:
parent
23b553ba06
commit
8571f7b041
|
@ -971,6 +971,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skeleton != RID()) {
|
if (skeleton != RID()) {
|
||||||
|
|
||||||
// calculate bone AABBs
|
// calculate bone AABBs
|
||||||
int bone_count = RasterizerStorage::base_singleton->skeleton_get_bone_count(skeleton);
|
int bone_count = RasterizerStorage::base_singleton->skeleton_get_bone_count(skeleton);
|
||||||
|
|
||||||
|
@ -981,39 +982,41 @@ public:
|
||||||
for (int j = 0; j < bone_count; j++) {
|
for (int j = 0; j < bone_count; j++) {
|
||||||
bptr[j].size = Vector2(-1, -1); //negative means unused
|
bptr[j].size = Vector2(-1, -1); //negative means unused
|
||||||
}
|
}
|
||||||
|
if (l && polygon->bones.size() == l * 4 && polygon->weights.size() == polygon->bones.size()) {
|
||||||
|
|
||||||
for (int j = 0; j < l; j++) {
|
for (int j = 0; j < l; j++) {
|
||||||
Point2 p = pp[j];
|
Point2 p = pp[j];
|
||||||
for (int k = 0; k < 4; k++) {
|
for (int k = 0; k < 4; k++) {
|
||||||
int idx = polygon->bones[j * 4 + k];
|
int idx = polygon->bones[j * 4 + k];
|
||||||
float w = polygon->weights[j * 4 + k];
|
float w = polygon->weights[j * 4 + k];
|
||||||
if (w == 0)
|
if (w == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bptr[idx].size.x < 0) {
|
if (bptr[idx].size.x < 0) {
|
||||||
//first
|
//first
|
||||||
bptr[idx] = Rect2(p, Vector2(0.00001, 0.00001));
|
bptr[idx] = Rect2(p, Vector2(0.00001, 0.00001));
|
||||||
} else {
|
} else {
|
||||||
bptr[idx].expand_to(p);
|
bptr[idx].expand_to(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Rect2 aabb;
|
Rect2 aabb;
|
||||||
bool first_bone = true;
|
bool first_bone = true;
|
||||||
for (int j = 0; j < bone_count; j++) {
|
for (int j = 0; j < bone_count; j++) {
|
||||||
Transform2D mtx = RasterizerStorage::base_singleton->skeleton_bone_get_transform_2d(skeleton, j);
|
Transform2D mtx = RasterizerStorage::base_singleton->skeleton_bone_get_transform_2d(skeleton, j);
|
||||||
Rect2 baabb = mtx.xform(bone_aabbs[j]);
|
Rect2 baabb = mtx.xform(bone_aabbs[j]);
|
||||||
|
|
||||||
if (first_bone) {
|
if (first_bone) {
|
||||||
aabb = baabb;
|
aabb = baabb;
|
||||||
first_bone = false;
|
first_bone = false;
|
||||||
} else {
|
} else {
|
||||||
aabb = aabb.merge(baabb);
|
aabb = aabb.merge(baabb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
r = r.merge(aabb);
|
r = r.merge(aabb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
Loading…
Reference in New Issue