Object: add ED_object_array_in_mode_or_selected
Use this utility function for render-shading & weight paint modes. This adds support for edit-mode & pose-mode where all objects in the mode are used in this case instead of the selected objects.
This commit is contained in:
@@ -365,6 +365,10 @@ struct Object **BKE_view_layer_array_selected_objects_params(
|
||||
uint *r_len,
|
||||
const struct ObjectsInViewLayerParams *params);
|
||||
|
||||
#define BKE_view_layer_array_selected_objects(view_layer, v3d, r_len, ...) \
|
||||
BKE_view_layer_array_selected_objects_params( \
|
||||
view_layer, v3d, r_len, &(const struct ObjectsInViewLayerParams)__VA_ARGS__)
|
||||
|
||||
struct ObjectsInModeParams {
|
||||
int object_mode;
|
||||
uint no_dup_data : 1;
|
||||
|
@@ -62,6 +62,11 @@ struct Object *ED_object_context(const struct bContext *C);
|
||||
struct Object *ED_object_active_context(const struct bContext *C);
|
||||
void ED_collection_hide_menu_draw(const struct bContext *C, struct uiLayout *layout);
|
||||
|
||||
Object **ED_object_array_in_mode_or_selected(struct bContext *C,
|
||||
bool (*filter_fn)(struct Object *ob, void *user_data),
|
||||
void *filter_user_data,
|
||||
uint *r_objects_len);
|
||||
|
||||
/* object_utils.c */
|
||||
bool ED_object_calc_active_center_for_editmode(struct Object *obedit,
|
||||
const bool select_only,
|
||||
|
@@ -145,6 +145,72 @@ Object *ED_object_active_context(const bContext *C)
|
||||
return ob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of objects:
|
||||
* - When in the property space, return the pinned or active object.
|
||||
* - When in edit-mode/pose-mode, return an array of objects in the mode.
|
||||
* - Otherwise return selected objects,
|
||||
* the callers \a filter_fn needs to check of they are editable
|
||||
* (assuming they need to be modified).
|
||||
*/
|
||||
Object **ED_object_array_in_mode_or_selected(bContext *C,
|
||||
bool (*filter_fn)(Object *ob, void *user_data),
|
||||
void *filter_user_data,
|
||||
uint *r_objects_len)
|
||||
{
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
Object *ob_active = OBACT(view_layer);
|
||||
Object **objects;
|
||||
|
||||
Object *ob = NULL;
|
||||
bool use_ob = true;
|
||||
if (area && (area->spacetype == SPACE_PROPERTIES)) {
|
||||
/* May return pinned object. */
|
||||
ob = ED_object_context(C);
|
||||
}
|
||||
else if (ob_active && (ob_active->mode &
|
||||
(OB_MODE_ALL_PAINT | OB_MODE_ALL_SCULPT | OB_MODE_ALL_PAINT_GPENCIL))) {
|
||||
/* When painting, limit to active. */
|
||||
ob = ob_active;
|
||||
}
|
||||
else {
|
||||
/* Otherwise use full selection. */
|
||||
use_ob = false;
|
||||
}
|
||||
|
||||
if (use_ob) {
|
||||
if ((ob != NULL) && !filter_fn(ob, filter_user_data)) {
|
||||
ob = NULL;
|
||||
}
|
||||
*r_objects_len = (ob != NULL) ? 1 : 0;
|
||||
objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__);
|
||||
if (ob != NULL) {
|
||||
objects[0] = ob;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const View3D *v3d = (area && area->spacetype == SPACE_VIEW3D) ? area->spacedata.first : NULL;
|
||||
/* When in a mode that supports multiple active objects, use "objects in mode"
|
||||
* instead of the object's selection. */
|
||||
if ((ob_active != NULL) && (ob_active->mode & (OB_MODE_EDIT | OB_MODE_POSE))) {
|
||||
objects = BKE_view_layer_array_from_objects_in_mode(
|
||||
view_layer,
|
||||
v3d,
|
||||
r_objects_len,
|
||||
{.no_dup_data = true, .filter_fn = filter_fn, .filter_userdata = filter_user_data});
|
||||
}
|
||||
else {
|
||||
objects = BKE_view_layer_array_selected_objects(
|
||||
view_layer,
|
||||
v3d,
|
||||
r_objects_len,
|
||||
{.no_dup_data = true, .filter_fn = filter_fn, .filter_userdata = filter_user_data});
|
||||
}
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@@ -84,54 +84,6 @@ static bool vertex_group_supported_poll_ex(bContext *C, const Object *ob);
|
||||
/** \name Local Utility Functions
|
||||
* \{ */
|
||||
|
||||
static Object **object_array_for_wpaint_impl(bContext *C,
|
||||
bool (*filter_fn)(struct Object *ob, void *user_data),
|
||||
void *filter_user_data,
|
||||
uint *r_objects_len)
|
||||
{
|
||||
Object **objects;
|
||||
|
||||
Object *ob = NULL;
|
||||
bool use_ob = true;
|
||||
if (CTX_wm_space_properties(C)) {
|
||||
/* May return pinned object. */
|
||||
ob = ED_object_context(C);
|
||||
}
|
||||
else if (CTX_data_mode_enum(C) == CTX_MODE_PAINT_WEIGHT) {
|
||||
/* When painting, limit to active. */
|
||||
ob = CTX_data_active_object(C);
|
||||
}
|
||||
else {
|
||||
/* Otherwise use full selection. */
|
||||
use_ob = false;
|
||||
}
|
||||
|
||||
if (use_ob) {
|
||||
if (!filter_fn(ob, filter_user_data)) {
|
||||
ob = NULL;
|
||||
}
|
||||
*r_objects_len = (ob != NULL) ? 1 : 0;
|
||||
objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__);
|
||||
if (ob != NULL) {
|
||||
objects[0] = ob;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
const View3D *v3d = CTX_wm_view3d(C); /* may be NULL. */
|
||||
objects = BKE_view_layer_array_selected_objects_params(
|
||||
view_layer,
|
||||
v3d,
|
||||
r_objects_len,
|
||||
&((const struct ObjectsInViewLayerParams){
|
||||
.no_dup_data = true,
|
||||
.filter_fn = filter_fn,
|
||||
.filter_userdata = filter_user_data,
|
||||
}));
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
static bool object_array_for_wpaint_filter(Object *ob, void *user_data)
|
||||
{
|
||||
bContext *C = user_data;
|
||||
@@ -143,7 +95,7 @@ static bool object_array_for_wpaint_filter(Object *ob, void *user_data)
|
||||
|
||||
static Object **object_array_for_wpaint(bContext *C, uint *r_objects_len)
|
||||
{
|
||||
return object_array_for_wpaint_impl(C, object_array_for_wpaint_filter, C, r_objects_len);
|
||||
return ED_object_array_in_mode_or_selected(C, object_array_for_wpaint_filter, C, r_objects_len);
|
||||
}
|
||||
|
||||
static bool vertex_group_use_vert_sel(Object *ob)
|
||||
|
@@ -102,51 +102,6 @@ static bool object_materials_supported_poll_ex(bContext *C, const Object *ob);
|
||||
/** \name Local Utilities
|
||||
* \{ */
|
||||
|
||||
static Object **object_array_for_shading_impl(bContext *C,
|
||||
bool (*filter_fn)(struct Object *ob,
|
||||
void *user_data),
|
||||
void *filter_user_data,
|
||||
uint *r_objects_len)
|
||||
{
|
||||
Object **objects;
|
||||
|
||||
Object *ob = NULL;
|
||||
bool use_ob = true;
|
||||
if (CTX_wm_space_properties(C)) {
|
||||
/* May return pinned object. */
|
||||
ob = ED_object_context(C);
|
||||
}
|
||||
else {
|
||||
/* Otherwise use full selection. */
|
||||
use_ob = false;
|
||||
}
|
||||
|
||||
if (use_ob) {
|
||||
if (!filter_fn(ob, filter_user_data)) {
|
||||
ob = NULL;
|
||||
}
|
||||
*r_objects_len = (ob != NULL) ? 1 : 0;
|
||||
objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__);
|
||||
if (ob != NULL) {
|
||||
objects[0] = ob;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
const View3D *v3d = CTX_wm_view3d(C); /* may be NULL. */
|
||||
objects = BKE_view_layer_array_selected_objects_params(
|
||||
view_layer,
|
||||
v3d,
|
||||
r_objects_len,
|
||||
&((const struct ObjectsInViewLayerParams){
|
||||
.no_dup_data = true,
|
||||
.filter_fn = filter_fn,
|
||||
.filter_userdata = filter_user_data,
|
||||
}));
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
static bool object_array_for_shading_edit_mode_enabled_filter(Object *ob, void *user_data)
|
||||
{
|
||||
bContext *C = user_data;
|
||||
@@ -160,7 +115,7 @@ static bool object_array_for_shading_edit_mode_enabled_filter(Object *ob, void *
|
||||
|
||||
static Object **object_array_for_shading_edit_mode_enabled(bContext *C, uint *r_objects_len)
|
||||
{
|
||||
return object_array_for_shading_impl(
|
||||
return ED_object_array_in_mode_or_selected(
|
||||
C, object_array_for_shading_edit_mode_enabled_filter, C, r_objects_len);
|
||||
}
|
||||
|
||||
@@ -177,7 +132,7 @@ static bool object_array_for_shading_edit_mode_disabled_filter(Object *ob, void
|
||||
|
||||
static Object **object_array_for_shading_edit_mode_disabled(bContext *C, uint *r_objects_len)
|
||||
{
|
||||
return object_array_for_shading_impl(
|
||||
return ED_object_array_in_mode_or_selected(
|
||||
C, object_array_for_shading_edit_mode_disabled_filter, C, r_objects_len);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user