Fix leaf Bone2Ds drawing in Polygon2D UV editor

This commit is contained in:
kleonc 2024-08-07 21:06:00 +02:00
parent 33fe10c065
commit 6b82c48bc6

View file

@ -1255,9 +1255,9 @@ void Polygon2DEditor::_uv_draw() {
//draw skeleton
NodePath skeleton_path = node->get_skeleton();
if (node->has_node(skeleton_path)) {
Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(node->get_node(skeleton_path));
Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(node->get_node_or_null(skeleton_path));
if (skeleton) {
Transform2D skeleton_xform = node->get_global_transform().affine_inverse().translated(-node->get_offset()) * skeleton->get_global_transform();
for (int i = 0; i < skeleton->get_bone_count(); i++) {
Bone2D *bone = skeleton->get_bone(i);
if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0)) {
@ -1276,7 +1276,7 @@ void Polygon2DEditor::_uv_draw() {
found_child = true;
Transform2D bone_xform = node->get_global_transform().affine_inverse().translated(-node->get_offset()) * (skeleton->get_global_transform() * bone->get_skeleton_rest());
Transform2D bone_xform = skeleton_xform * bone->get_skeleton_rest();
Transform2D endpoint_xform = bone_xform * n->get_transform();
Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5);
@ -1286,8 +1286,8 @@ void Polygon2DEditor::_uv_draw() {
if (!found_child) {
//draw normally
Transform2D bone_xform = node->get_global_transform().affine_inverse().translated(-node->get_offset()) * (skeleton->get_global_transform() * bone->get_skeleton_rest());
Transform2D endpoint_xform = bone_xform * Transform2D(0, Vector2(bone->get_length(), 0));
Transform2D bone_xform = skeleton_xform * bone->get_skeleton_rest();
Transform2D endpoint_xform = bone_xform * Transform2D(0, Vector2(bone->get_length(), 0)).rotated(bone->get_bone_angle());
Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5);
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE));
@ -1295,7 +1295,6 @@ void Polygon2DEditor::_uv_draw() {
}
}
}
}
//draw paint circle
uv_edit_draw->draw_circle(bone_paint_pos, bone_paint_radius->get_value() * EDSCALE, Color(1, 1, 1, 0.1));