[Bf-blender-cvs] [3ef54e21cf8] temp-collection-assets: Various cleanups (comments, API, naming, etc)
Julian Eisel
noreply at git.blender.org
Wed Jan 12 11:12:13 CET 2022
Commit: 3ef54e21cf85e7296214b43affc4bc98ac56b4b6
Author: Julian Eisel
Date: Tue Jan 11 21:29:08 2022 +0100
Branches: temp-collection-assets
https://developer.blender.org/rB3ef54e21cf85e7296214b43affc4bc98ac56b4b6
Various cleanups (comments, API, naming, etc)
===================================================================
M source/blender/blenkernel/BKE_collection.h
M source/blender/blenkernel/intern/collection.c
M source/blender/editors/space_view3d/space_view3d.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index 900ea594972..35d8c93d2b0 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -53,6 +53,19 @@ typedef struct CollectionParent {
struct Collection *collection;
} CollectionParent;
+/**
+ * Options to control how object visibility flags should affect operations. Used for bounding-box
+ * calculations, for example.
+ */
+typedef enum CollectionObjectVisibility {
+ /** Include all objects linked to the scene, regardless of visibility flags. */
+ COLLECTION_VISIBILITY_ALL_OBJECTS,
+ /** Exclude objects hidden with the render visibility flag. */
+ COLLECTION_VISIBILITY_RENDER,
+ /** Exclude objects hidden with the viewport visibility flag. */
+ COLLECTION_VISIBILITY_VIEWPORT
+} CollectionObjectVisibility;
+
/* Collections */
/**
@@ -216,15 +229,20 @@ struct Base *BKE_collection_or_layer_objects(const struct ViewLayer *view_layer,
/**
* Calculate the axis-aligned bounding box (in global space) of all objects in this collection,
- * excluding empties (but including lamps, cameras, curves, etc.).
+ * excluding empties (but including lamps, cameras, curves, etc.). Nested collections and
+ * collection instances are included.
*/
void BKE_collection_boundbox_calc(const struct Collection *collection,
+ CollectionObjectVisibility object_visibility,
struct BoundBox *r_boundbox);
/**
* Calculate the axis-aligned dimensions of all objects in this collection, excluding
- * empties (but including lamps, cameras, curves, etc.).
+ * empties (but including lamps, cameras, curves, etc.). Nested collections and collection
+ * instances are included.
*/
-void BKE_collection_dimensions_calc(const struct Collection *collection, float r_vec[3]);
+void BKE_collection_dimensions_calc(const struct Collection *collection,
+ CollectionObjectVisibility object_visibility,
+ float r_vec[3]);
/* Editing. */
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 76d46591dd7..762a9465097 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -371,7 +371,8 @@ static void collection_blend_read_expand(BlendExpander *expander, ID *id)
static IDProperty *collection_asset_dimensions_property(Collection *collection)
{
float dimensions[3];
- BKE_collection_dimensions_calc(collection, dimensions);
+ /* Use the bounding-box for what the user sees, i.e. use viewport visibility. */
+ BKE_collection_dimensions_calc(collection, COLLECTION_VISIBILITY_VIEWPORT, dimensions);
if (is_zero_v3(dimensions)) {
return NULL;
}
@@ -892,57 +893,68 @@ Base *BKE_collection_or_layer_objects(const ViewLayer *view_layer, Collection *c
* \{ */
/**
- * \param with_instances: Include the objects of instance collections.
* \param with_empties: Include the location of empties in the bounding box.
* \param instance_mat: The transform matrix of the object instancing this collection. Pass the
* unit matrix if the collection is not an instance.
*/
-static void collection_geometry_boundbox_calc_recursive(const Collection *collection,
- const bool with_instances,
- const bool with_empties,
- float instance_mat[4][4],
- float r_min[3],
- float r_max[3])
-{
- LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
- if (with_instances && cob->ob->instance_collection) {
- float this_instance_collection_mat[4][4];
- unit_m4(this_instance_collection_mat);
- sub_v3_v3(this_instance_collection_mat[3], cob->ob->instance_collection->instance_offset);
- mul_m4_m4m4(this_instance_collection_mat, cob->ob->obmat, instance_mat);
-
- collection_geometry_boundbox_calc_recursive(cob->ob->instance_collection,
- with_instances,
+static void collection_geometry_boundbox_calc_recursive(
+ const Collection *parent_collection,
+ const CollectionObjectVisibility object_visibility,
+ const bool with_empties,
+ float parent_instance_mat[4][4],
+ float r_min[3],
+ float r_max[3])
+{
+ LISTBASE_FOREACH (const CollectionObject *, cob, &parent_collection->gobject) {
+ Object *ob = cob->ob;
+
+ if (ob->instance_collection) {
+ float child_collection_mat[4][4];
+ unit_m4(child_collection_mat);
+ sub_v3_v3(child_collection_mat[3], ob->instance_collection->instance_offset);
+ mul_m4_m4m4(child_collection_mat, ob->obmat, parent_instance_mat);
+
+ collection_geometry_boundbox_calc_recursive(ob->instance_collection,
+ object_visibility,
with_empties,
- this_instance_collection_mat,
+ child_collection_mat,
r_min,
r_max);
}
+ if ((object_visibility == COLLECTION_VISIBILITY_RENDER) &&
+ (ob->visibility_flag & OB_HIDE_RENDER)) {
+ continue;
+ }
+ if ((object_visibility == COLLECTION_VISIBILITY_VIEWPORT) &&
+ (ob->visibility_flag & OB_HIDE_VIEWPORT)) {
+ continue;
+ }
+
/* Empties don't contribute to the dimensions. */
- if (!with_empties && (cob->ob->type == OB_EMPTY)) {
+ if (!with_empties && (ob->type == OB_EMPTY)) {
continue;
}
- BoundBox *bb_object = BKE_object_boundbox_get(cob->ob);
+ BoundBox *bb_object = BKE_object_boundbox_get(ob);
if (bb_object) {
float obmat[4][4];
- mul_m4_m4m4(obmat, cob->ob->obmat, instance_mat);
-
+ mul_m4_m4m4(obmat, ob->obmat, parent_instance_mat);
BKE_boundbox_minmax(bb_object, obmat, r_min, r_max);
}
else {
- minmax_v3v3_v3(r_min, r_max, cob->ob->obmat[3]);
+ minmax_v3v3_v3(r_min, r_max, ob->obmat[3]);
}
}
- LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
+ LISTBASE_FOREACH (CollectionChild *, child, &parent_collection->children) {
collection_geometry_boundbox_calc_recursive(
- child->collection, with_instances, with_empties, instance_mat, r_min, r_max);
+ child->collection, object_visibility, with_empties, parent_instance_mat, r_min, r_max);
}
}
static void collection_boundbox_min_max(const Collection *collection,
+ const CollectionObjectVisibility object_visibility,
float r_min[3],
float r_max[3])
{
@@ -953,21 +965,24 @@ static void collection_boundbox_min_max(const Collection *collection,
unit_m4(instance_collection_mat);
collection_geometry_boundbox_calc_recursive(
- collection, true, false, instance_collection_mat, r_min, r_max);
+ collection, object_visibility, false, instance_collection_mat, r_min, r_max);
}
-void BKE_collection_boundbox_calc(const Collection *collection, BoundBox *r_boundbox)
+void BKE_collection_boundbox_calc(const Collection *collection,
+ const CollectionObjectVisibility object_visibility,
+ BoundBox *r_boundbox)
{
float min[3], max[3];
- collection_boundbox_min_max(collection, min, max);
+ collection_boundbox_min_max(collection, object_visibility, min, max);
BKE_boundbox_init_from_minmax(r_boundbox, min, max);
}
-/* TODO invisible objects (either in scene or in viewport)? */
-void BKE_collection_dimensions_calc(const Collection *collection, float r_vec[3])
+void BKE_collection_dimensions_calc(const Collection *collection,
+ const CollectionObjectVisibility object_visibility,
+ float r_vec[3])
{
float min[3], max[3];
- collection_boundbox_min_max(collection, min, max);
+ collection_boundbox_min_max(collection, object_visibility, min, max);
sub_v3_v3v3(r_vec, max, min);
}
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index f021df0b836..b4705619bee 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -530,7 +530,7 @@ static void view3d_boundbox_drop_draw_activate(struct wmDropBox *drop, wmDrag *d
}
else if (drag_id_type == ID_GR) {
struct Collection *collection = (struct Collection *)WM_drag_get_local_ID(drag, ID_GR);
- BKE_collection_dimensions_calc(collection, dimensions);
+ BKE_collection_dimensions_calc(collection, COLLECTION_VISIBILITY_VIEWPORT, dimensions);
}
else {
BLI_assert_unreachable();
@@ -813,7 +813,9 @@ static void view3d_collection_drop_matrix_get(const Collection *collection,
unit_m4((float(*)[])unit_mat);
BoundBox boundbox;
- BKE_collection_boundbox_calc(collection, &boundbox);
+ /* Use the bounding-box for what the user will see, i.e. use viewport visibility. */
+ const CollectionObjectVisibility visibility = COLLECTION_VISIBILITY_VIEWPORT;
+ BKE_collection_boundbox_calc(collection, visibility, &boundbox);
view3d_drop_matrix_from_snap(snap_state, &boundbox, unit_mat, r_mat_final);
}
More information about the Bf-blender-cvs
mailing list