Blender V5.3
info_stats.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdio>
10#include <cstring>
11
12#include <fmt/format.h>
13
14#include "MEM_guardedalloc.h"
15
16#include "DNA_armature_types.h"
17#include "DNA_curve_types.h"
19#include "DNA_lattice_types.h"
20#include "DNA_mesh_types.h"
21#include "DNA_meta_types.h"
23#include "DNA_scene_types.h"
24#include "DNA_space_enums.h"
26
27#include "BLF_api.hh"
28
29#include "BLI_array_utils.hh"
30#include "BLI_enum_flags.hh"
31#include "BLI_listbase.hh"
32#include "BLI_math_geom_c.hh"
33#include "BLI_set.hh"
34#include "BLI_span.hh"
35#include "BLI_string.hh"
36#include "BLI_string_utf8.hh"
37#include "BLI_timecode.hh"
38
39#include "BLT_translation.hh"
40
41#include "BKE_action.hh"
42#include "BKE_armature.hh"
43#include "BKE_blender_version.h"
44#include "BKE_curve.hh"
45#include "BKE_curves.hh"
46#include "BKE_editmesh.hh"
47#include "BKE_grease_pencil.hh"
48#include "BKE_key.hh"
49#include "BKE_layer.hh"
50#include "BKE_main.hh"
51#include "BKE_mesh.hh"
52#include "BKE_object.hh"
53#include "BKE_paint.hh"
54#include "BKE_paint_bvh.hh"
55#include "BKE_scene.hh"
56#include "BKE_subdiv_ccg.hh"
58
60
61#include "ED_info.hh"
62
63#include "WM_api.hh"
64
65#include "GPU_capabilities.hh"
66
67namespace blender {
68
86
107
108static bool stats_mesheval(const Mesh *mesh_eval, bool is_selected, SceneStats *stats)
109{
110 if (mesh_eval == nullptr) {
111 return false;
112 }
113
114 int totvert, totedge, totface, totloop;
115
116 /* Get multires stats. */
117 if (const std::unique_ptr<SubdivCCG> &subdiv_ccg = mesh_eval->runtime->subdiv_ccg) {
118 BKE_subdiv_ccg_topology_counters(*subdiv_ccg, totvert, totedge, totface, totloop);
119 }
120 else {
121 /* Get CPU subdivided mesh if it exists. */
122 const SubsurfRuntimeData *subsurf_runtime_data = nullptr;
123 if (mesh_eval->runtime->mesh_eval) {
124 mesh_eval = mesh_eval->runtime->mesh_eval;
125 }
126 else {
127 subsurf_runtime_data = mesh_eval->runtime->subsurf_runtime_data;
128 }
129
130 /* Get GPU subdivision stats if they exist. If there is no 3D viewport or the mesh is
131 * hidden it will not be subdivided, fall back to unsubdivided in that case. */
132 if (subsurf_runtime_data && subsurf_runtime_data->has_gpu_subdiv &&
133 subsurf_runtime_data->stats_totvert)
134 {
135 totvert = subsurf_runtime_data->stats_totvert;
136 totedge = subsurf_runtime_data->stats_totedge;
137 totface = subsurf_runtime_data->stats_faces_num;
138 totloop = subsurf_runtime_data->stats_totloop;
139 }
140 else {
141 totvert = mesh_eval->verts_num;
142 totedge = mesh_eval->edges_num;
143 totface = mesh_eval->faces_num;
144 totloop = mesh_eval->corners_num;
145 }
146 }
147
148 stats->totvert += totvert;
149 stats->totedge += totedge;
150 stats->totface += totface;
151
152 const int tottri = poly_to_tri_count(totface, totloop);
153 stats->tottri += tottri;
154
155 if (is_selected) {
156 stats->totvertsel += totvert;
157 stats->totedgesel += totedge;
158 stats->totfacesel += totface;
159 stats->tottrisel += tottri;
160 }
161 return true;
162}
163
164static void stats_object(Object *ob,
165 const View3D *v3d_local,
166 SceneStats *stats,
167 Set<const Mesh *> &objects_gset)
168{
170 return;
171 }
172
173 if (v3d_local && !BKE_object_is_visible_in_viewport(v3d_local, ob)) {
174 return;
175 }
176
177 const bool is_selected = (ob->base_flag & BASE_SELECTED) != 0;
178
179 stats->totobj++;
180 if (is_selected) {
181 stats->totobjsel++;
182 }
183
184 switch (ob->type) {
185 case OB_MESH: {
186 /* we assume evaluated mesh is already built, this strictly does stats now. */
187 const Mesh *mesh_eval = BKE_object_get_evaluated_mesh_no_subsurf(ob);
188 if (!objects_gset.add(mesh_eval)) {
189 break;
190 }
191 stats_mesheval(mesh_eval, is_selected, stats);
192 break;
193 }
194 case OB_LAMP:
195 stats->totlamp++;
196 if (is_selected) {
197 stats->totlampsel++;
198 }
199 break;
200 case OB_GREASE_PENCIL: {
201 if (!is_selected) {
202 break;
203 }
204
205 const GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
206
207 for (const GreasePencilDrawingBase *drawing_base : grease_pencil->drawings()) {
208 const GreasePencilDrawing *drawing = reinterpret_cast<const GreasePencilDrawing *>(
209 drawing_base);
210 const bke::CurvesGeometry &curves = drawing->wrap().strokes();
211
212 stats->totpoints += curves.points_num();
213 stats->totgpstroke += curves.curves_num();
214 }
215
216 for (const bke::greasepencil::Layer *layer : grease_pencil->layers()) {
217 stats->totgpframe += layer->frames().size();
218 }
219
220 stats->totgplayer += grease_pencil->layers().size();
221 break;
222 }
223 case OB_CURVES: {
224 const Curves &curves_id = *id_cast<Curves *>(ob->data);
225 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
226 stats->totpoints += curves.points_num();
227 break;
228 }
229 case OB_POINTCLOUD:
230 case OB_VOLUME: {
231 break;
232 }
233 default:
234 break;
235 }
236}
237
238static void stats_object_edit(Object *obedit, SceneStats *stats)
239{
240 if (obedit->type == OB_MESH) {
241 const BMesh *bm = BKE_editmesh_bmesh_get(obedit);
242
243 stats->totvert += bm->totvert;
244 stats->totvertsel += bm->totvertsel;
245
246 stats->totedge += bm->totedge;
247 stats->totedgesel += bm->totedgesel;
248
249 stats->totface += bm->totface;
250 stats->totfacesel += bm->totfacesel;
251
253 }
254 else if (obedit->type == OB_ARMATURE) {
255 /* Armature Edit */
256 bArmature *arm = id_cast<bArmature *>(obedit->data);
257
258 for (EditBone &ebo : *arm->edbo) {
259 stats->totbone++;
260
261 if ((ebo.flag & BONE_CONNECTED) && ebo.parent) {
262 stats->totvert--;
263 }
264
265 if (ebo.flag & BONE_TIPSEL) {
266 stats->totvertsel++;
267 }
268 if (ebo.flag & BONE_ROOTSEL) {
269 stats->totvertsel++;
270 }
271
272 if (ebo.flag & BONE_SELECTED) {
273 stats->totbonesel++;
274 }
275
276 /* if this is a connected child and its parent is being moved, remove our root */
277 if ((ebo.flag & BONE_CONNECTED) && (ebo.flag & BONE_ROOTSEL) && ebo.parent &&
278 (ebo.parent->flag & BONE_TIPSEL))
279 {
280 stats->totvertsel--;
281 }
282
283 stats->totvert += 2;
284 }
285 }
286 else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) { /* OB_FONT has no cu->editnurb */
287 /* Curve Edit */
288 Curve *cu = id_cast<Curve *>(obedit->data);
289 BezTriple *bezt;
290 BPoint *bp;
291 int a;
292 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(cu);
293
294 for (Nurb &nu : *nurbs) {
295 int selection_count = stats->totpointsel;
296 if (nu.type == CU_BEZIER) {
297 bezt = nu.bezt;
298 a = nu.pntsu;
299 while (a--) {
300 stats->totpoints += 3;
301 if (bezt->f1 & SELECT) {
302 stats->totpointsel++;
303 }
304 if (bezt->f2 & SELECT) {
305 stats->totpointsel++;
306 }
307 if (bezt->f3 & SELECT) {
308 stats->totpointsel++;
309 }
310 bezt++;
311 }
312 selection_count = (stats->totpointsel - selection_count) == (nu.pntsu * 3);
313 }
314 else {
315 bp = nu.bp;
316 a = nu.pntsu * nu.pntsv;
317 while (a--) {
318 stats->totpoints++;
319 if (bp->f1 & SELECT) {
320 stats->totpointsel++;
321 }
322 bp++;
323 }
324 selection_count = (stats->totpointsel - selection_count) == (nu.pntsu * nu.pntsv);
325 }
326 stats->totcurves++;
327 stats->totcurvesel += selection_count;
328 }
329 }
330 else if (obedit->type == OB_MBALL) {
331 /* MetaBall Edit */
332 MetaBall *mball = id_cast<MetaBall *>(obedit->data);
333
334 for (MetaElem &ml : *mball->editelems) {
335 stats->totvert++;
336 if (ml.flag & SELECT) {
337 stats->totvertsel++;
338 }
339 }
340 }
341 else if (obedit->type == OB_LATTICE) {
342 /* Lattice Edit */
343 Lattice *lt = id_cast<Lattice *>(obedit->data);
344 Lattice *editlatt = lt->editlatt->latt;
345 BPoint *bp;
346 int a;
347
348 bp = editlatt->def;
349
350 a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw;
351 while (a--) {
352 stats->totvert++;
353 if (bp->f1 & SELECT) {
354 stats->totvertsel++;
355 }
356 bp++;
357 }
358 }
359 else if (obedit->type == OB_CURVES) {
360 const Curves &curves_id = *id_cast<Curves *>(obedit->data);
361 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
362 if (const bke::AttributeReader selection = curves.attributes().lookup<bool>(".selection")) {
363 const OffsetIndices points_by_curve = curves.points_by_curve();
364 struct SelectionCounts {
365 int point;
366 int curve;
367 };
368 const SelectionCounts counts = threading::parallel_reduce(
369 points_by_curve.index_range(),
370 2048,
371 SelectionCounts{0, 0},
372 [&](const IndexRange range, SelectionCounts value) {
373 for (const int curve : range) {
374 if (selection.domain == bke::AttrDomain::Point) {
375 const int selected_points = array_utils::count_booleans(*selection,
376 points_by_curve[curve]);
377 value.point += selected_points;
378 value.curve += (selected_points > 0);
379 }
380 else {
381 const bool selected = selection.varray[curve];
382 value.point += selected ? points_by_curve[curve].size() : 0;
383 value.curve += selected;
384 }
385 }
386 return value;
387 },
388 [&](const SelectionCounts &a, const SelectionCounts &b) {
389 return SelectionCounts{a.point + b.point, a.curve + b.curve};
390 });
391 stats->totpointsel += counts.point;
392 stats->totcurvesel += counts.curve;
393 }
394 else {
395 stats->totpointsel += curves.points_num();
396 stats->totcurvesel += curves.curves_num();
397 }
398
399 stats->totpoints += curves.points_num();
400 stats->totcurves += curves.curves_num();
401 }
402 else if (obedit->type == OB_POINTCLOUD) {
403 PointCloud &pointcloud = *id_cast<PointCloud *>(obedit->data);
404 const VArray<bool> selection = *pointcloud.attributes().lookup_or_default<bool>(
405 ".selection", bke::AttrDomain::Point, true);
406 stats->totvertsel = array_utils::count_booleans(selection);
407 stats->totpoints = pointcloud.totpoint;
408 }
409}
410
411static void stats_object_pose(const Object *ob, SceneStats *stats)
412{
413 if (ob->pose) {
414 bArmature *arm = id_cast<bArmature *>(ob->data);
415
416 for (bPoseChannel &pchan : ob->pose->chanbase) {
417 stats->totbone++;
418 if ((pchan.flag & POSE_SELECTED)) {
419 if (BKE_pose_is_bonecoll_visible(arm, &pchan)) {
420 stats->totbonesel++;
421 }
422 }
423 }
424 }
425}
426
428{
429 return (ob->mode == OB_MODE_SCULPT && ob->runtime->sculpt_session &&
431}
432
433static void stats_object_mesh_paint(const Object *ob, SceneStats *stats)
434{
435 const SculptSession *ss = ob->runtime->sculpt_session;
437 if (ss == nullptr || pbvh == nullptr) {
438 return;
439 }
440
441 switch (pbvh->type()) {
443 const Mesh &mesh = *id_cast<const Mesh *>(ob->data);
444 stats->totvertactive = mesh.verts_num;
445 stats->totfaceactive = mesh.faces_num;
446 break;
447 }
451 break;
455 break;
456 }
457}
458
459/* Statistics displayed in info header. Called regularly on scene changes. */
460static void stats_update(const Main *bmain,
461 Depsgraph *depsgraph,
462 const Scene *scene,
463 ViewLayer *view_layer,
464 View3D *v3d_local,
465 SceneStats *stats)
466{
467 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
468 const Object *ob = BKE_view_layer_active_object_get(view_layer);
469 const Object *obedit = BKE_view_layer_edit_object_get(view_layer);
470
471 memset(stats, 0x0, sizeof(*stats));
472
473 if (obedit && (ob->type != OB_GREASE_PENCIL)) {
474 /* Edit Mode. */
475 FOREACH_OBJECT_BEGIN (bmain, scene, view_layer, ob_iter) {
476 if (ob_iter->base_flag & BASE_ENABLED_AND_VISIBLE_IN_DEFAULT_VIEWPORT) {
477 if (ob_iter->mode & OB_MODE_EDIT) {
478 stats_object_edit(ob_iter, stats);
479 stats->totobjsel++;
480 }
481 else {
482 /* Skip hidden objects in local view that are not in edit-mode,
483 * an exception for edit-mode, in most other modes these would be considered hidden. */
484 if (v3d_local && !BKE_object_is_visible_in_viewport(v3d_local, ob_iter)) {
485 continue;
486 }
487 }
488 stats->totobj++;
489 }
490 }
492 }
493 else if (ob && (ob->mode & OB_MODE_POSE)) {
494 /* Pose Mode. */
495 FOREACH_OBJECT_BEGIN (bmain, scene, view_layer, ob_iter) {
496 if (ob_iter->base_flag & BASE_ENABLED_AND_VISIBLE_IN_DEFAULT_VIEWPORT) {
497 if (ob_iter->mode & OB_MODE_POSE) {
498 stats_object_pose(ob_iter, stats);
499 stats->totobjsel++;
500 }
501 else {
502 /* See comment for edit-mode. */
503 if (v3d_local && !BKE_object_is_visible_in_viewport(v3d_local, ob_iter)) {
504 continue;
505 }
506 }
507 stats->totobj++;
508 }
509 }
511 }
512 else if (ob && BKE_object_use_sculptsession(ob->mode)) {
513 stats_object_mesh_paint(ob, stats);
514 }
515 else if (ob && ob->mode == OB_MODE_SCULPT_CURVES) {
516 const Curves &curves_id = *id_cast<Curves *>(ob->data);
517 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
518 stats->totvertactive += curves.points_num();
519 }
520 else {
521 /* Objects. */
522 Set<const Mesh *> objects_gset;
523 DEGObjectIterSettings deg_iter_settings{};
524 deg_iter_settings.depsgraph = depsgraph;
526 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, ob_iter) {
527 stats_object(ob_iter, v3d_local, stats, objects_gset);
528 }
530 }
531}
532
534{
535 MEM_SAFE_DELETE(view_layer->stats);
536
537 for (wmWindow &win : wm->windows) {
538 ViewLayer *view_layer_test = WM_window_get_active_view_layer(&win);
539 if (view_layer != view_layer_test) {
540 continue;
541 }
542 const bScreen *screen = WM_window_get_active_screen(&win);
543 for (ScrArea &area : screen->areabase) {
544 if (area.spacetype == SPACE_VIEW3D) {
545 View3D *v3d = area.spacedata.first_as<View3D>();
546 if (v3d->localvd) {
548 }
549 }
550 }
551 }
552}
553
555{
556 MEM_SAFE_DELETE(v3d->runtime.local_stats);
557}
558
559static bool format_stats(
560 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, SceneStatsFmt *stats_fmt)
561{
562 /* Create stats if they don't already exist. */
563 SceneStats **stats_p = (v3d_local) ? &v3d_local->runtime.local_stats : &view_layer->stats;
564 if (*stats_p == nullptr) {
565 /* Don't access dependency graph if interface is marked as locked. */
566 wmWindowManager *wm = bmain->wm.first();
567 if (wm->runtime->is_interface_locked) {
568 return false;
569 }
570 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
571 *stats_p = MEM_new_uninitialized<SceneStats>(__func__);
572 stats_update(bmain, depsgraph, scene, view_layer, v3d_local, *stats_p);
573 }
574
575 SceneStats *stats = *stats_p;
576
577 /* Generate formatted numbers. */
578#define SCENE_STATS_FMT_INT(_id) BLI_str_format_uint64_grouped(stats_fmt->_id, stats->_id)
579
580 SCENE_STATS_FMT_INT(totvert);
581 SCENE_STATS_FMT_INT(totvertsel);
582 SCENE_STATS_FMT_INT(totvertactive);
583
584 SCENE_STATS_FMT_INT(totedge);
585 SCENE_STATS_FMT_INT(totedgesel);
586
587 SCENE_STATS_FMT_INT(totface);
588 SCENE_STATS_FMT_INT(totfacesel);
589 SCENE_STATS_FMT_INT(totfaceactive);
590
591 SCENE_STATS_FMT_INT(totbone);
592 SCENE_STATS_FMT_INT(totbonesel);
593
594 SCENE_STATS_FMT_INT(totobj);
595 SCENE_STATS_FMT_INT(totobjsel);
596
597 SCENE_STATS_FMT_INT(totlamp);
598 SCENE_STATS_FMT_INT(totlampsel);
599
600 SCENE_STATS_FMT_INT(tottri);
601 SCENE_STATS_FMT_INT(tottrisel);
602 SCENE_STATS_FMT_INT(tottriactive);
603
604 SCENE_STATS_FMT_INT(totgplayer);
605 SCENE_STATS_FMT_INT(totgpframe);
606 SCENE_STATS_FMT_INT(totgpstroke);
607
608 SCENE_STATS_FMT_INT(totpoints);
609 SCENE_STATS_FMT_INT(totpointsel);
610 SCENE_STATS_FMT_INT(totcurves);
611 SCENE_STATS_FMT_INT(totcurvesel);
612
613#undef SCENE_STATS_FMT_INT
614 return true;
615}
616
617static void get_stats_string(char *info,
618 int len,
619 size_t *ofs,
620 const Main &bmain,
621 const Scene *scene,
622 ViewLayer *view_layer,
623 SceneStatsFmt *stats_fmt)
624{
625 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
627 eObjectMode object_mode = ob ? ob->mode : OB_MODE_OBJECT;
628 LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer);
629
630 if (object_mode == OB_MODE_OBJECT) {
631 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
632 len - *ofs,
633 "%s | ",
634 BKE_collection_ui_name_get(layer_collection->collection));
635 }
636
637 if (ob) {
638 *ofs += BLI_snprintf_utf8_rlen(info + *ofs, len - *ofs, "%s | ", ob->id.name + 2);
639 }
640
641 if ((ob) && (ob->type == OB_GREASE_PENCIL)) {
642 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
643 len - *ofs,
644
645 IFACE_("Layers:%s | Frames:%s | Strokes:%s | Points:%s"),
646 stats_fmt->totgplayer,
647 stats_fmt->totgpframe,
648 stats_fmt->totgpstroke,
649 stats_fmt->totpoints);
650 return;
651 }
652
653 if (ob && ob->mode == OB_MODE_EDIT) {
654 if (BKE_keyblock_from_object(ob)) {
655 *ofs += BLI_strncpy_utf8_rlen(info + *ofs, IFACE_("(Key) "), len - *ofs);
656 }
657
658 if (ob->type == OB_MESH) {
659 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
660 len - *ofs,
661
662 IFACE_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"),
663 stats_fmt->totvertsel,
664 stats_fmt->totvert,
665 stats_fmt->totedgesel,
666 stats_fmt->totedge,
667 stats_fmt->totfacesel,
668 stats_fmt->totface,
669 stats_fmt->tottri);
670 }
671 else if (ob->type == OB_ARMATURE) {
672 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
673 len - *ofs,
674
675 IFACE_("Joints:%s/%s | Bones:%s/%s"),
676 stats_fmt->totvertsel,
677 stats_fmt->totvert,
678 stats_fmt->totbonesel,
679 stats_fmt->totbone);
680 }
681 else if (ob->type == OB_CURVES) {
682 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
683 len - *ofs,
684 IFACE_("Points:%s/%s"),
685 stats_fmt->totvertsel,
686 stats_fmt->totpoints);
687 }
688 else if (ob->type == OB_POINTCLOUD) {
689 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
690 len - *ofs,
691 IFACE_("Points:%s/%s"),
692 stats_fmt->totvertsel,
693 stats_fmt->totpoints);
694 }
695 else {
696 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
697 len - *ofs,
698 IFACE_("Verts:%s/%s"),
699 stats_fmt->totvertsel,
700 stats_fmt->totvert);
701 }
702 }
703 else if (ob && (object_mode & OB_MODE_POSE)) {
705 info + *ofs, len - *ofs, IFACE_("Bones:%s/%s"), stats_fmt->totbonesel, stats_fmt->totbone);
706 }
707 else if (ob && (ob->type == OB_CURVES)) {
708 const char *count = (object_mode == OB_MODE_SCULPT_CURVES) ? stats_fmt->totvertactive :
709 stats_fmt->totpoints;
710 *ofs += BLI_snprintf_utf8_rlen(info + *ofs, len - *ofs, IFACE_("Points:%s"), count);
711 }
712 else if (ob && BKE_object_use_sculptsession(ob->mode)) {
714 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
715 len - *ofs,
716
717 IFACE_("Verts:%s | Tris:%s"),
718 stats_fmt->totvertactive,
719 stats_fmt->tottriactive);
720 }
721 else {
722 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
723 len - *ofs,
724
725 IFACE_("Verts:%s | Faces:%s"),
726 stats_fmt->totvertactive,
727 stats_fmt->totfaceactive);
728 }
729 }
730 else {
731 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
732 len - *ofs,
733
734 IFACE_("Verts:%s | Faces:%s | Tris:%s"),
735 stats_fmt->totvert,
736 stats_fmt->totface,
737 stats_fmt->tottri);
738 }
739
740 if (!STREQ(&stats_fmt->totobj[0], "0")) {
741 *ofs += BLI_snprintf_utf8_rlen(info + *ofs,
742 len - *ofs,
743
744 IFACE_(" | Objects:%s/%s"),
745 stats_fmt->totobjsel,
746 stats_fmt->totobj);
747 }
748}
749
751 Scene *scene,
752 ViewLayer *view_layer,
753 const char statusbar_flag)
754{
755 char formatted_mem[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE];
756 size_t ofs = 0;
757 static char info[384];
758 int len = sizeof(info);
759
760 info[0] = '\0';
761
762 /* Scene statistics. */
763 if (statusbar_flag & STATUSBAR_SHOW_STATS) {
764 SceneStatsFmt stats_fmt;
765 if (format_stats(bmain, scene, view_layer, nullptr, &stats_fmt)) {
766 get_stats_string(info + ofs, len, &ofs, *bmain, scene, view_layer, &stats_fmt);
767 }
768 }
769
770 /* Scene Duration. */
771 if (statusbar_flag & STATUSBAR_SHOW_SCENE_DURATION) {
772 if (info[0]) {
773 ofs += BLI_snprintf_utf8_rlen(info + ofs, len - ofs, " | ");
774 }
775 const int relative_current_frame = (scene->r.cfra - scene->r.sfra) + 1;
776 const int frame_count = (scene->r.efra - scene->r.sfra) + 1;
777 char timecode[32];
779 sizeof(timecode),
780 -2,
781 FRA2TIME(frame_count),
782 scene->frames_per_second(),
783 U.timecode_style);
784 const std::string scene_duration = fmt::format(
785 fmt::runtime(IFACE_("Duration: {} (Frame {}/{})")),
786 timecode,
787 relative_current_frame,
788 frame_count);
789 ofs += BLI_strncpy_utf8_rlen(info + ofs, scene_duration.c_str(), len - ofs);
790 }
791
792 /* Memory status. */
793 if (statusbar_flag & STATUSBAR_SHOW_MEMORY) {
794 if (info[0]) {
795 ofs += BLI_snprintf_utf8_rlen(info + ofs, len - ofs, " | ");
796 }
797 uintptr_t mem_in_use = MEM_get_memory_in_use();
798 BLI_str_format_byte_unit(formatted_mem, mem_in_use, false);
799 ofs += BLI_snprintf_utf8_rlen(info + ofs, len - ofs, IFACE_("Memory: %s"), formatted_mem);
800 }
801
802 /* GPU VRAM status. */
803 if ((statusbar_flag & STATUSBAR_SHOW_VRAM) && GPU_mem_stats_supported()) {
804 int gpu_free_mem_kb, gpu_tot_mem_kb;
805 GPU_mem_stats_get(&gpu_tot_mem_kb, &gpu_free_mem_kb);
806 float gpu_total_gb = gpu_tot_mem_kb / 1048576.0f;
807 float gpu_free_gb = gpu_free_mem_kb / 1048576.0f;
808 if (info[0]) {
809 ofs += BLI_snprintf_utf8_rlen(info + ofs, len - ofs, " | ");
810 }
811 if (gpu_free_mem_kb && gpu_tot_mem_kb) {
812 ofs += BLI_snprintf_utf8_rlen(info + ofs,
813 len - ofs,
814
815 IFACE_("VRAM: %.1f/%.1f GiB"),
816 gpu_total_gb - gpu_free_gb,
817 gpu_total_gb);
818 }
819 else {
820 /* Can only show amount of GPU VRAM available. */
822 info + ofs, len - ofs, IFACE_("VRAM: %.1f GiB Free"), gpu_free_gb);
823 }
824 }
825
826 /* Blender version. */
827 if (statusbar_flag & STATUSBAR_SHOW_VERSION) {
828 if (info[0]) {
829 ofs += BLI_snprintf_utf8_rlen(info + ofs, len - ofs, " | ");
830 }
832 info + ofs, len - ofs, IFACE_("%s"), BKE_blender_version_string_compact());
833 }
834
835 return info;
836}
837
838const char *ED_info_statusbar_string(Main *bmain, Scene *scene, ViewLayer *view_layer)
839{
840 return ED_info_statusbar_string_ex(bmain, scene, view_layer, U.statusbar_flag);
841}
842
843const char *ED_info_statistics_string(Main *bmain, Scene *scene, ViewLayer *view_layer)
844{
845 const eUserpref_StatusBar_Flag statistics_status_bar_flag = STATUSBAR_SHOW_STATS |
849
850 return ED_info_statusbar_string_ex(bmain, scene, view_layer, statistics_status_bar_flag);
851}
852
853static void stats_row(int col1,
854 const char *key,
855 int col2,
856 const char *value1,
857 const char *value2,
858 int *y,
859 int height)
860{
861 *y -= height;
862 BLF_draw_default(col1, *y, 0.0f, key, 128);
863 char values[128];
864 SNPRINTF_UTF8(values, (value2) ? "%s / %s" : "%s", value1, value2);
865 BLF_draw_default(col2, *y, 0.0f, values, sizeof(values));
866}
867
869 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, int x, int *y, int height)
870{
871 BLI_assert(v3d_local == nullptr || v3d_local->localvd != nullptr);
872 SceneStatsFmt stats_fmt;
873 if (!format_stats(bmain, scene, view_layer, v3d_local, &stats_fmt)) {
874 return;
875 }
876
877 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
879 eObjectMode object_mode = ob ? ob->mode : OB_MODE_OBJECT;
880 const int font_id = BLF_default();
881
882 /* Translated labels for each stat row. */
883 enum {
884 OBJ,
885 VERTS,
886 EDGES,
887 FACES,
888 TRIS,
889 JOINTS,
890 BONES,
891 LAYERS,
892 FRAMES,
893 STROKES,
894 POINTS,
895 LIGHTS,
896 CURVES,
897 MAX_LABELS_COUNT
898 };
899 char labels[MAX_LABELS_COUNT][64];
900
901 STRNCPY_UTF8(labels[OBJ], IFACE_("Objects"));
902 STRNCPY_UTF8(labels[VERTS], IFACE_("Vertices"));
903 STRNCPY_UTF8(labels[EDGES], IFACE_("Edges"));
904 STRNCPY_UTF8(labels[FACES], IFACE_("Faces"));
905 STRNCPY_UTF8(labels[TRIS], IFACE_("Triangles"));
906 STRNCPY_UTF8(labels[JOINTS], IFACE_("Joints"));
907 STRNCPY_UTF8(labels[BONES], IFACE_("Bones"));
908 STRNCPY_UTF8(labels[LAYERS], IFACE_("Layers"));
909 STRNCPY_UTF8(labels[FRAMES], IFACE_("Frames"));
910 STRNCPY_UTF8(labels[STROKES], IFACE_("Strokes"));
911 STRNCPY_UTF8(labels[POINTS], IFACE_("Points"));
912 STRNCPY_UTF8(labels[LIGHTS], IFACE_("Lights"));
913 STRNCPY_UTF8(labels[CURVES], IFACE_("Curves"));
914
915 int longest_label = 0;
916 for (int i = 0; i < MAX_LABELS_COUNT; ++i) {
917 longest_label = max_ii(longest_label, BLF_width(font_id, labels[i], sizeof(labels[i])));
918 }
919
920 int col1 = x;
921 int col2 = x + longest_label + (0.5f * U.widget_unit);
922
923 /* Add some extra margin above this section. */
924 *y -= (0.6f * height);
925
926 bool any_objects = !STREQ(&stats_fmt.totobj[0], "0");
927 bool any_selected = !STREQ(&stats_fmt.totobjsel[0], "0");
928
929 if (any_selected) {
930 stats_row(col1, labels[OBJ], col2, stats_fmt.totobjsel, stats_fmt.totobj, y, height);
931 }
932 else if (any_objects) {
933 stats_row(col1, labels[OBJ], col2, stats_fmt.totobj, nullptr, y, height);
934 /* Show scene totals if nothing is selected. */
935 stats_row(col1, labels[VERTS], col2, stats_fmt.totvert, nullptr, y, height);
936 stats_row(col1, labels[EDGES], col2, stats_fmt.totedge, nullptr, y, height);
937 stats_row(col1, labels[FACES], col2, stats_fmt.totface, nullptr, y, height);
938 stats_row(col1, labels[TRIS], col2, stats_fmt.tottri, nullptr, y, height);
939 return;
940 }
941 else if (object_mode != OB_MODE_SCULPT_CURVES && !BKE_object_use_sculptsession(object_mode)) {
942 /* No objects in scene. */
943 stats_row(col1, labels[OBJ], col2, stats_fmt.totobj, nullptr, y, height);
944 return;
945 }
946
947 if ((ob) && ob->type == OB_GREASE_PENCIL) {
948 stats_row(col1, labels[LAYERS], col2, stats_fmt.totgplayer, nullptr, y, height);
949 stats_row(col1, labels[FRAMES], col2, stats_fmt.totgpframe, nullptr, y, height);
950 stats_row(col1, labels[STROKES], col2, stats_fmt.totgpstroke, nullptr, y, height);
951 stats_row(col1, labels[POINTS], col2, stats_fmt.totpoints, nullptr, y, height);
952 }
953 else if (ob && ob->mode == OB_MODE_EDIT) {
954 if (ob->type == OB_MESH) {
955 stats_row(col1, labels[VERTS], col2, stats_fmt.totvertsel, stats_fmt.totvert, y, height);
956 stats_row(col1, labels[EDGES], col2, stats_fmt.totedgesel, stats_fmt.totedge, y, height);
957 stats_row(col1, labels[FACES], col2, stats_fmt.totfacesel, stats_fmt.totface, y, height);
958 stats_row(col1, labels[TRIS], col2, stats_fmt.tottri, nullptr, y, height);
959 }
960 else if (ob->type == OB_ARMATURE) {
961 stats_row(col1, labels[JOINTS], col2, stats_fmt.totvertsel, stats_fmt.totvert, y, height);
962 stats_row(col1, labels[BONES], col2, stats_fmt.totbonesel, stats_fmt.totbone, y, height);
963 }
964 else if (ob->type == OB_POINTCLOUD) {
965 stats_row(col1, labels[POINTS], col2, stats_fmt.totvertsel, stats_fmt.totpoints, y, height);
966 }
967 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF, OB_CURVES)) {
968 stats_row(col1, labels[POINTS], col2, stats_fmt.totpointsel, stats_fmt.totpoints, y, height);
969 stats_row(col1, labels[CURVES], col2, stats_fmt.totcurvesel, stats_fmt.totcurves, y, height);
970 }
971 else if (ob->type != OB_FONT) {
972 stats_row(col1, labels[VERTS], col2, stats_fmt.totvertsel, stats_fmt.totvert, y, height);
973 }
974 }
975 else if (ob && BKE_object_use_sculptsession(object_mode)) {
977 stats_row(col1, labels[VERTS], col2, stats_fmt.totvertactive, nullptr, y, height);
978 stats_row(col1, labels[TRIS], col2, stats_fmt.tottriactive, nullptr, y, height);
979 }
980 else {
981 stats_row(col1, labels[VERTS], col2, stats_fmt.totvertactive, nullptr, y, height);
982 stats_row(col1, labels[FACES], col2, stats_fmt.totfaceactive, nullptr, y, height);
983 }
984 }
985 else if (ob && (object_mode & OB_MODE_SCULPT_CURVES)) {
986 stats_row(col1, labels[VERTS], col2, stats_fmt.totvertactive, nullptr, y, height);
987 }
988 else if (ob && (object_mode & OB_MODE_POSE)) {
989 stats_row(col1, labels[BONES], col2, stats_fmt.totbonesel, stats_fmt.totbone, y, height);
990 }
991 else if ((ob) && (ob->type == OB_LAMP)) {
992 stats_row(col1, labels[LIGHTS], col2, stats_fmt.totlampsel, stats_fmt.totlamp, y, height);
993 }
994 else if ((object_mode == OB_MODE_OBJECT) && ob && ELEM(ob->type, OB_MESH, OB_FONT)) {
995 /* Object mode with the active object a mesh or text object. */
996 stats_row(col1, labels[VERTS], col2, stats_fmt.totvertsel, stats_fmt.totvert, y, height);
997 stats_row(col1, labels[EDGES], col2, stats_fmt.totedgesel, stats_fmt.totedge, y, height);
998 stats_row(col1, labels[FACES], col2, stats_fmt.totfacesel, stats_fmt.totface, y, height);
999 stats_row(col1, labels[TRIS], col2, stats_fmt.tottrisel, stats_fmt.tottri, y, height);
1000 }
1001}
1002
1003} // namespace blender
Blender kernel action and pose functionality.
Low-level operations for curves.
Low-level operations for grease pencil.
#define FOREACH_OBJECT_END
Definition BKE_layer.hh:533
#define FOREACH_OBJECT_BEGIN(_bmain, _scene, _view_layer, _instance)
Definition BKE_layer.hh:523
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
A BVH for high poly meshes.
#define BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE
Definition BLI_string.hh:31
#define BLI_STR_FORMAT_UINT64_GROUPED_SIZE
Definition BLI_string.hh:22
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define IFACE_(msgid)
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
#define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS
#define FRA2TIME(a)
Read Blender memory allocation and freeing.
#define ELEM(...)
#define STREQ(a, b)
AttributeSet attributes
bool add(const Key &key)
Definition BLI_set.hh:248
#define layer
#define SCENE_STATS_FMT_INT(_id)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
int64_t count_booleans(const VArray< bool > &varray)
pbvh::Tree * pbvh_get(Object &object)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:127
BMesh Iterators.
void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], long long int bytes, bool base_10) ATTR_NONNULL(1)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
static bool format_stats(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, SceneStatsFmt *stats_fmt)
const char * ED_info_statistics_string(Main *bmain, Scene *scene, ViewLayer *view_layer)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
static void stats_row(int col1, const char *key, int col2, const char *value1, const char *value2, int *y, int height)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
const char * BKE_collection_ui_name_get(Collection *collection)
@ BASE_ENABLED_AND_VISIBLE_IN_DEFAULT_VIEWPORT
char size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
@ STATUSBAR_SHOW_SCENE_DURATION
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1407
MINLINE int max_ii(int a, int b)
int BKE_sculpt_get_grid_num_faces(const Object &object)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
static void stats_object_edit(Object *obedit, SceneStats *stats)
void GPU_mem_stats_get(int *r_totalmem, int *r_freemem)
bool GPU_mem_stats_supported()
static void get_stats_string(char *info, int len, size_t *ofs, const Main &bmain, const Scene *scene, ViewLayer *view_layer, SceneStatsFmt *stats_fmt)
size_t(*) MEM_get_memory_in_use()
static void stats_update(void *arg, RenderStats *rs)
LayerCollection * BKE_view_layer_active_collection_get(ViewLayer *view_layer)
const char * ED_info_statusbar_string(Main *bmain, Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_edit_object_get(const ViewLayer *view_layer)
@ OB_MODE_SCULPT_CURVES
void ED_view3d_local_stats_free(View3D *v3d)
int BLF_default()
int BKE_sculpt_get_grid_num_verts(const Object &object)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool BKE_object_use_sculptsession(eObjectMode mode)
Definition object.cc:4328
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
_W64 unsigned int uintptr_t
Definition BKE_text.h:120
bool BKE_object_is_visible_in_viewport(const View3D *v3d, const Object *ob)
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
static bool stats_is_object_dynamic_topology_sculpt(const Object *ob)
size_t BLI_timecode_string_from_time(char *str, size_t maxncpy, int brevity_level, float time_seconds, double fps, short timecode_style) ATTR_NONNULL()
Definition timecode.cc:24
void ED_info_stats_clear(wmWindowManager *wm, ViewLayer *view_layer)
const char * BKE_blender_version_string_compact()
Definition blender.cc:152
static void stats_object(Object *ob, const View3D *v3d_local, SceneStats *stats, Set< const Mesh * > &objects_gset)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
static void stats_object_mesh_paint(const Object *ob, SceneStats *stats)
ListBaseT< Nurb > * BKE_curve_editNurbs_get(Curve *cu)
Definition curve.cc:441
void BKE_subdiv_ccg_topology_counters(const SubdivCCG &subdiv_ccg, int &r_num_vertices, int &r_num_edges, int &r_num_faces, int &r_num_loops)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
static void stats_object_pose(const Object *ob, SceneStats *stats)
bool BKE_pose_is_bonecoll_visible(const bArmature *arm, const bPoseChannel *pchan) ATTR_WARN_UNUSED_RESULT
void ED_info_draw_stats(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, int x, int *y, int height)
bScreen * WM_window_get_active_screen(const wmWindow *win)
size_t BLI_snprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
Mesh * BKE_object_get_evaluated_mesh_no_subsurf(const Object *object_eval)
Definition object.cc:4419
static bool stats_mesheval(const Mesh *mesh_eval, bool is_selected, SceneStats *stats)
const char * ED_info_statusbar_string_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, const char statusbar_flag)
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
struct Lattice * latt
char name[258]
Definition DNA_ID.h:433
struct EditLatt * editlatt
struct BPoint * def
struct Collection * collection
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
bke::MeshRuntime * runtime
ListBaseT< MetaElem > * editelems
eMetaElem_Flag flag
bke::ObjectRuntime * runtime
struct bPose * pose
char totvertactive[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:90
char tottrisel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:97
char totlampsel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:96
char totvert[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:89
char tottri[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:97
char totgpframe[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
char totlamp[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:96
char totedgesel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:92
char totbonesel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:94
char totface[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:91
char totedge[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:92
char totbone[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:94
char totcurvesel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
char totgplayer[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:99
char totpointsel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
char totvertsel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:89
char tottriactive[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:98
char totfacesel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:91
char totcurves[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
char totobjsel[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:95
char totobj[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:95
char totgpstroke[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
char totfaceactive[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
Definition info_stats.cc:93
char totpoints[BLI_STR_FORMAT_UINT64_GROUPED_SIZE]
struct RenderData r
ListBaseT< SpaceLink > spacedata
struct SceneStats * local_stats
struct View3D * localvd
View3D_Runtime runtime
struct SceneStats * stats
ListBaseT< EditBone > * edbo
ListBaseT< bPoseChannel > chanbase
ListBaseT< struct ScrArea > areabase
std::unique_ptr< SubdivCCG > subdiv_ccg
SubsurfRuntimeData * subsurf_runtime_data