|
5 | 5 | from ..ui.hud import text as hud_text |
6 | 6 | from ..ui.hud.text import draw as hud_text_draw, measure as hud_text_measure |
7 | 7 |
|
| 8 | +# Object types whose data block carries material slots — gates the material |
| 9 | +# stat line so empties/lights/cameras don't show a useless "No material". |
| 10 | +_MATERIAL_OBJECT_TYPES = frozenset( |
| 11 | + {"MESH", "CURVE", "SURFACE", "META", "FONT", |
| 12 | + "GREASEPENCIL", "GPENCIL", "VOLUME", "POINTCLOUD"} |
| 13 | +) |
| 14 | + |
8 | 15 |
|
9 | 16 | def draw_iops_statistics(): |
10 | 17 | context = bpy.context |
@@ -73,6 +80,101 @@ def _dim(text): |
73 | 80 | _t(file_status, role=value_role, x=base_column_x) |
74 | 81 | offset_y -= row_step |
75 | 82 |
|
| 83 | + unit_settings = context.scene.unit_settings |
| 84 | + |
| 85 | + def _fmt_len(value): |
| 86 | + if unit_settings.system != "NONE": |
| 87 | + return bpy.utils.units.to_string( |
| 88 | + unit_settings.system, "LENGTH", |
| 89 | + value * unit_settings.scale_length, precision=2) |
| 90 | + return f"{value:.2f}" |
| 91 | + |
| 92 | + if active_object: |
| 93 | + if prefs.show_dimensions_stat: |
| 94 | + dims = active_object.dimensions |
| 95 | + if dims.x or dims.y or dims.z: |
| 96 | + _t("Dims:", role=Role.HUD_LABEL) |
| 97 | + _t(" x ".join(_fmt_len(d) for d in dims), |
| 98 | + role=Role.HUD_LABEL_ACTIVE, x=base_column_x) |
| 99 | + offset_y -= row_step |
| 100 | + |
| 101 | + if prefs.show_view_position_stat: |
| 102 | + loc = active_object.matrix_world.translation |
| 103 | + value = f"{loc.x:.2f}, {loc.y:.2f}, {loc.z:.2f}" |
| 104 | + rv3d = space_3d.region_3d if space_3d else None |
| 105 | + if rv3d: |
| 106 | + dist = (rv3d.view_matrix @ loc).length |
| 107 | + value += f" Dist: {_fmt_len(dist)}" |
| 108 | + _t("Pos:", role=Role.HUD_LABEL) |
| 109 | + _t(value, role=Role.HUD_LABEL_ACTIVE, x=base_column_x) |
| 110 | + offset_y -= row_step |
| 111 | + |
| 112 | + if (prefs.show_material_stat |
| 113 | + and active_object.type in _MATERIAL_OBJECT_TYPES): |
| 114 | + slots = active_object.material_slots |
| 115 | + filled = sum(1 for slot in slots if slot.material) |
| 116 | + mat = active_object.active_material |
| 117 | + segments = [] |
| 118 | + if mat: |
| 119 | + name = mat.name |
| 120 | + if prefs.show_material_users_stat and mat.users > 1: |
| 121 | + name += f" ({mat.users} users)" |
| 122 | + segments.append((f"{name} [{filled}/{len(slots)}]", |
| 123 | + Role.HUD_LABEL_ACTIVE)) |
| 124 | + else: |
| 125 | + segments.append(("No material", Role.HUD_STATS_ERROR)) |
| 126 | + if slots and filled < len(slots): |
| 127 | + segments.append(("Empty slots", Role.HUD_STATS_ERROR)) |
| 128 | + _t("Mat:", role=Role.HUD_LABEL) |
| 129 | + col_x = base_column_x |
| 130 | + for seg_text, seg_role in segments: |
| 131 | + _t(seg_text, role=seg_role, x=col_x) |
| 132 | + w, _h = _dim(seg_text) |
| 133 | + col_x += w + 6 |
| 134 | + offset_y -= row_step |
| 135 | + |
| 136 | + if prefs.show_modifiers_stat and active_object.modifiers: |
| 137 | + mods = active_object.modifiers |
| 138 | + count = str(len(mods)) |
| 139 | + _t("Mods:", role=Role.HUD_LABEL) |
| 140 | + _t(count, role=Role.HUD_LABEL_ACTIVE, x=base_column_x) |
| 141 | + if any(m.show_viewport != m.show_render for m in mods): |
| 142 | + w, _h = _dim(count) |
| 143 | + _t("viewport ≠ render", role=Role.HUD_STATS_ERROR, |
| 144 | + x=base_column_x + w + 6) |
| 145 | + offset_y -= row_step |
| 146 | + |
| 147 | + if prefs.show_instances_stat: |
| 148 | + obj_data = getattr(active_object, "data", None) |
| 149 | + if obj_data is not None: |
| 150 | + users = obj_data.users - (1 if obj_data.use_fake_user else 0) |
| 151 | + if users > 1: |
| 152 | + _t("Instances:", role=Role.HUD_LABEL) |
| 153 | + _t(str(users), role=Role.HUD_STATS_ERROR, |
| 154 | + x=base_column_x) |
| 155 | + offset_y -= row_step |
| 156 | + |
| 157 | + if prefs.show_parent_stat and (active_object.parent |
| 158 | + or active_object.constraints): |
| 159 | + _t("Parent:", role=Role.HUD_LABEL) |
| 160 | + col_x = base_column_x |
| 161 | + if active_object.parent: |
| 162 | + parent_name = active_object.parent.name |
| 163 | + _t(parent_name, role=Role.HUD_LABEL_ACTIVE, x=col_x) |
| 164 | + w, _h = _dim(parent_name) |
| 165 | + col_x += w + 6 |
| 166 | + constraint_count = len(active_object.constraints) |
| 167 | + if constraint_count: |
| 168 | + _t(f"+{constraint_count} constraints", |
| 169 | + role=Role.HUD_LABEL_ACTIVE, x=col_x) |
| 170 | + offset_y -= row_step |
| 171 | + |
| 172 | + if prefs.show_units_stat and unit_settings.scale_length != 1.0: |
| 173 | + _t("Units:", role=Role.HUD_LABEL) |
| 174 | + _t(f"scale {unit_settings.scale_length:g}", |
| 175 | + role=Role.HUD_STATS_ERROR, x=base_column_x) |
| 176 | + offset_y -= row_step |
| 177 | + |
76 | 178 | if active_object and active_object.type == "MESH": |
77 | 179 | scale_stat = [] |
78 | 180 | scale = active_object.scale |
|
0 commit comments