[Bf-blender-cvs] [1de2f53] temp_localview_split: Add/use BKE object visibility checks using correct logic
Julian Eisel
noreply at git.blender.org
Wed Aug 10 03:04:20 CEST 2016
Commit: 1de2f534cf9d90b1510a5144e4c5899f0dd246d1
Author: Julian Eisel
Date: Wed Aug 10 02:59:38 2016 +0200
Branches: temp_localview_split
https://developer.blender.org/rB1de2f534cf9d90b1510a5144e4c5899f0dd246d1
Add/use BKE object visibility checks using correct logic
Avoids code duplication and makes handling visibility easier (also for my further layer manager work).
Was a bit afraid of doing this since I wasn't sure if it's possible to handle all cases nicely, but turned out to work quite well and it really improves readability.
===================================================================
M source/blender/blenkernel/BKE_localview.h
M source/blender/blenkernel/BKE_object.h
M source/blender/blenkernel/intern/object.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/object/object_edit.c
M source/blender/editors/object/object_relations.c
M source/blender/editors/object/object_select.c
M source/blender/editors/render/render_internal.c
M source/blender/editors/screen/screen_context.c
M source/blender/editors/sculpt_paint/paint_image_proj.c
M source/blender/editors/space_view3d/drawobject.c
M source/blender/editors/space_view3d/space_view3d.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/editors/space_view3d/view3d_edit.c
M source/blender/editors/space_view3d/view3d_select.c
M source/blender/editors/space_view3d/view3d_view.c
M source/blender/editors/transform/transform_conversions.c
M source/blender/editors/transform/transform_manipulator.c
M source/blender/editors/transform/transform_orientations.c
M source/blender/editors/transform/transform_snap_object.c
M source/blender/gpu/intern/gpu_draw.c
M source/blender/makesdna/DNA_scene_types.h
M source/blender/render/intern/source/convertblender.c
M source/blender/render/intern/source/envmap.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_localview.h b/source/blender/blenkernel/BKE_localview.h
index 6499742..6443f5c 100644
--- a/source/blender/blenkernel/BKE_localview.h
+++ b/source/blender/blenkernel/BKE_localview.h
@@ -40,24 +40,21 @@
/* Forcing inline as some of these are called a lot, mostly in loops even. */
BLI_INLINE bool BKE_localview_info_cmp(LocalViewInfo a, LocalViewInfo b) ATTR_WARN_UNUSED_RESULT;
-BLI_INLINE bool BKE_localview_is_object_visible(View3D *v3d, Object *ob) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
BLI_INLINE bool BKE_localview_is_valid(LocalViewInfo localview) ATTR_WARN_UNUSED_RESULT;
BLI_INLINE void BKE_localview_object_assign(View3D *v3d, Object *ob) ATTR_NONNULL();
BLI_INLINE void BKE_localview_object_unassign(View3D *v3d, Object *ob) ATTR_NONNULL();
-/* visibility checks */
+/**
+ * Local view main visibility checks.
+ * \return if \a a is visible in \a b, or the other way around (order doesn't matter).
+ */
BLI_INLINE bool BKE_localview_info_cmp(LocalViewInfo a, LocalViewInfo b)
{
return (a.viewbits & b.viewbits) != 0;
}
-BLI_INLINE bool BKE_localview_is_object_visible(View3D *v3d, Object *ob)
-{
- return (v3d->localviewd == NULL) || BKE_localview_info_cmp(v3d->localviewd->info, ob->localview);
-}
-
/**
* Check if \a localview defines a visible local view.
*/
@@ -67,7 +64,7 @@ BLI_INLINE bool BKE_localview_is_valid(LocalViewInfo localview)
}
/**
- * Adjust local view info of \a ob to be visible if \a v3d is in local view
+ * Adjust local view info of \a ob to be visible if \a v3d is in local view.
*/
BLI_INLINE void BKE_localview_object_assign(View3D *v3d, Object *ob)
{
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 1b3e05d..46c6079 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -33,7 +33,10 @@
extern "C" {
#endif
+#include "BKE_localview.h"
+
#include "BLI_compiler_attrs.h"
+#include "BLI_utildefines.h"
struct Base;
struct EvaluationContext;
@@ -97,6 +100,33 @@ void *BKE_object_obdata_add_from_type(
int type, const char *name)
ATTR_NONNULL(1);
+/**
+ * Object visibility check for layer or local view and optionally Object.restrictflag.
+ *
+ * \param view_lay: Layers to check for (e.g. Scene.lay or View3D.lay).
+ * \param localview: Can be NULL if not in local view (or to ignore it).
+ */
+ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
+BLI_INLINE bool BKE_object_is_visible(
+ const struct Object *ob, const unsigned int view_lay, const LocalViewInfo *localview,
+ const bool check_restrictflag)
+{
+ const bool is_localview = localview && BKE_localview_is_valid(*localview);
+ return (is_localview ? BKE_localview_info_cmp(*localview, ob->localview) : (ob->lay & view_lay)) &&
+ (!check_restrictflag || (ob->restrictflag & OB_RESTRICT_VIEW) == 0);
+}
+/**
+ * Object visibility check for \a v3d, checking layer or local view
+ * (if \a v3d is in local view) and optionally Object.restrictflag.
+ */
+ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
+BLI_INLINE bool BKE_object_v3d_is_visible(
+ const struct Object *ob, const struct View3D *v3d,
+ const bool check_restrictflag)
+{
+ return BKE_object_is_visible(ob, v3d->lay, (v3d->localviewd) ? &v3d->localviewd->info : NULL, check_restrictflag);
+}
+
void BKE_object_lod_add(struct Object *ob);
void BKE_object_lod_sort(struct Object *ob);
bool BKE_object_lod_remove(struct Object *ob, int level);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index f5b593e..d736a45 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -96,7 +96,6 @@
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
#include "BKE_linestyle.h"
-#include "BKE_localview.h"
#include "BKE_mesh.h"
#include "BKE_editmesh.h"
#include "BKE_mball.h"
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 97ad1c7..50c6170 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -49,7 +49,7 @@
#include "BKE_context.h"
#include "BKE_gpencil.h"
-#include "BKE_localview.h"
+#include "BKE_object.h"
#include "BKE_tracking.h"
#include "BKE_action.h"
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 8d441ab..a08c17b 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -70,7 +70,6 @@
#include "BKE_image.h"
#include "BKE_lattice.h"
#include "BKE_library.h"
-#include "BKE_localview.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mball.h"
@@ -144,10 +143,7 @@ static int object_hide_view_clear_exec(bContext *C, wmOperator *UNUSED(op))
/* XXX need a context loop to handle such cases */
for (base = FIRSTBASE; base; base = base->next) {
- if ((base->lay & v3d->lay) &&
- BKE_localview_is_object_visible(v3d, base->object) &&
- (base->object->restrictflag & OB_RESTRICT_VIEW))
- {
+ if (BKE_object_v3d_is_visible(base->object, v3d, false) && (base->object->restrictflag & OB_RESTRICT_VIEW)) {
if (!(base->object->restrictflag & OB_RESTRICT_SELECT)) {
base->flag |= SELECT;
}
@@ -486,7 +482,7 @@ void ED_object_editmode_enter(bContext *C, int flag)
return;
}
else if (v3d) {
- if ((base->lay & v3d->lay) == 0 || !BKE_localview_is_object_visible(v3d, base->object)) {
+ if (!BKE_object_v3d_is_visible(base->object, v3d, false)) {
return;
}
}
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index a753b51..60dff2c 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -76,7 +76,6 @@
#include "BKE_lattice.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
-#include "BKE_localview.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mball.h"
diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c
index b534c22..cddc8fd 100644
--- a/source/blender/editors/object/object_select.c
+++ b/source/blender/editors/object/object_select.c
@@ -53,12 +53,12 @@
#include "BKE_group.h"
#include "BKE_main.h"
#include "BKE_material.h"
+#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_property.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_library.h"
-#include "BKE_localview.h"
#include "BKE_deform.h"
#include "WM_api.h"
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index 7d80167..936f4c1 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -58,7 +58,6 @@
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_library.h"
-#include "BKE_localview.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_object.h"
@@ -793,7 +792,7 @@ static void clean_viewport_memory(Main *bmain, Scene *scene, LocalViewInfo *loca
}
for (SETLOOPER(scene, sce_iter, base)) {
- if ((base->lay & renderlay) == 0 || BKE_localview_info_cmp(*localview, base->object->localview) == 0) {
+ if (!BKE_object_is_visible(base->object, renderlay, localview, false)) {
continue;
}
if (RE_allow_render_generic_object(base->object)) {
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c
index c1d2ea5..5742d1b 100644
--- a/source/blender/editors/screen/screen_context.c
+++ b/source/blender/editors/screen/screen_context.c
@@ -47,7 +47,6 @@
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_gpencil.h"
-#include "BKE_localview.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
@@ -82,12 +81,6 @@ static LocalViewInfo context_localviews(bScreen *sc, ScrArea *sa_ctx)
return views;
}
-/* helper to check for local view if needed */
-BLI_INLINE bool localview_check(LocalViewInfo localviews, Base *base)
-{
- return !BKE_localview_is_valid(localviews) || BKE_localview_info_cmp(localviews, base->object->localview);
-}
-
const char *screen_context_dir[] = {
"scene", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
"selected_objects", "selected_bases",
@@ -137,13 +130,11 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
const bool visible_objects = CTX_data_equals(member, "visible_objects");
for (base = scene->base.first; base; base = base->next) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->lay & lay)) {
- if (localview_check(localviews, base)) {
- if (visible_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
+ if (BKE_object_is_visible(base->object, lay, &localviews, true)) {
+ if (visible_objects)
+ CTX_data_id_list_add(result, &base->object->id);
+ else
+ CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
}
}
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
@@ -155,8 +146,8 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
const bool selectable_objects = CTX_data_equals(member, "selectable_objects");
for (base = scene->base.first; base; base = base->next) {
- if ((base->object->restrictflag & (OB_RESTRICT_VIEW | OB_RESTRICT_SELECT)) == 0 && (base->lay & lay)) {
- if (localview_check(localviews, base)) {
+ if ((base->object->restrictflag & OB_RESTRICT_SELECT) == 0) {
+ if (BKE_object_is_visible(base->object, lay, &localviews, true)) {
if (selectable_objects)
CTX_data_id_list_add(result, &base->object->id);
else
@@ -173,13 +164,11 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
const bool selected_objects = CTX_data_equals(member, "selected_objects");
for (base = scene->base.first; base; base = base->next) {
- if ((base->flag & SELECT) && (base->lay & lay)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list