Groups and collection: editing group collections

Allow users to edit either the object group active collection or view layer one

We can't support users selecting the group collections from the outliner group
because that would be imply having an active group for the scene or workspace.

But the way it is now allows to see and edit the collection values after the
group is instanced.
This commit is contained in:
Dalai Felinto 2017-11-30 18:38:07 -02:00
parent aeaf87bbeb
commit f91e057786
7 changed files with 80 additions and 23 deletions

View File

@ -27,6 +27,16 @@ class CollectionButtonsPanel:
bl_context = "collection"
def get_collection_from_context(context):
active_object = context.active_object
if active_object and active_object.dupli_group and context.space_data.collection_context == 'GROUP':
group = active_object.dupli_group
return group.view_layer.collections.active
else:
return context.layer_collection
class COLLECTION_PT_context_collection(CollectionButtonsPanel, Panel):
bl_label = ""
bl_options = {'HIDE_HEADER'}
@ -34,8 +44,14 @@ class COLLECTION_PT_context_collection(CollectionButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
space = context.space_data
active_object = context.active_object
collection = context.layer_collection
if active_object and active_object.dupli_group:
split = layout.split(percentage=0.2)
split.row().prop(space, "collection_context", expand=True)
layout = split
collection = get_collection_from_context(context)
name = collection.name
if name == 'Master Collection':
layout.label(text=name, icon='COLLAPSEMENU')
@ -54,7 +70,7 @@ class COLLECTION_PT_clay_settings(CollectionButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
scene_props = context.scene.collection_properties['BLENDER_CLAY']
collection = context.layer_collection
collection = get_collection_from_context(context)
collection_props = collection.engine_overrides['BLENDER_CLAY']
col = layout.column()
@ -81,7 +97,7 @@ class COLLECTION_PT_object_mode_settings(CollectionButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
scene_props = context.scene.collection_properties['ObjectMode']
collection = context.layer_collection
collection = get_collection_from_context(context)
collection_props = collection.engine_overrides['ObjectMode']
col = layout.column()
@ -100,7 +116,7 @@ class COLLECTION_PT_edit_mode_settings(CollectionButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
scene_props = context.scene.collection_properties['EditMode']
collection = context.layer_collection
collection = get_collection_from_context(context)
collection_props = collection.engine_overrides['EditMode']
col = layout.column()
@ -124,7 +140,7 @@ class COLLECTION_PT_paint_weight_mode_settings(CollectionButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
scene_props = context.scene.collection_properties['WeightPaintMode']
collection = context.layer_collection
collection = get_collection_from_context(context)
collection_props = collection.engine_overrides['WeightPaintMode']
col = layout.column()
@ -143,7 +159,7 @@ class COLLECTION_PT_paint_vertex_mode_settings(CollectionButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
scene_props = context.scene.collection_properties['VertexPaintMode']
collection = context.layer_collection
collection = get_collection_from_context(context)
collection_props = collection.engine_overrides['VertexPaintMode']
col = layout.column()

View File

@ -39,6 +39,7 @@
#include "BLT_translation.h"
#include "DNA_armature_types.h"
#include "DNA_group_types.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
@ -177,7 +178,7 @@ static int buttons_context_path_workspace(ButsContextPath *path)
return RNA_struct_is_a(ptr->type, &RNA_WorkSpace);
}
static int buttons_context_path_collection(ButsContextPath *path)
static int buttons_context_path_collection(ButsContextPath *path, eSpaceButtons_Collection_Context collection_context)
{
PointerRNA *ptr = &path->ptr[path->len - 1];
@ -187,10 +188,21 @@ static int buttons_context_path_collection(ButsContextPath *path)
}
ViewLayer *view_layer = ptr->data;
LayerCollection *sc = BKE_layer_collection_get_active(view_layer);
if (sc) {
RNA_pointer_create(NULL, &RNA_LayerCollection, sc, &path->ptr[path->len]);
if (collection_context == SB_COLLECTION_CTX_GROUP) {
Object *ob = OBACT(view_layer);
if (ob && ob->dup_group) {
view_layer = ob->dup_group->view_layer;
/* Replace the view layer by the group in the context path. */
RNA_pointer_create(NULL, &RNA_Group, ob->dup_group, &path->ptr[path->len - 1]);
}
}
LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
if (layer_collection) {
RNA_pointer_create(NULL, &RNA_LayerCollection, layer_collection, &path->ptr[path->len]);
path->len++;
return 1;
}
@ -650,7 +662,7 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
found = buttons_context_path_workspace(path);
break;
case BCONTEXT_COLLECTION:
found = buttons_context_path_collection(path);
found = buttons_context_path_collection(path, sbuts->collection_context);
break;
case BCONTEXT_OBJECT:
case BCONTEXT_PHYSICS:

View File

@ -65,6 +65,7 @@ typedef struct ButsContextPath {
int len;
int flag;
int tex_ctx;
int collection_ctx;
} ButsContextPath;
typedef struct ButsTextureUser {

View File

@ -781,15 +781,24 @@ static eOLDrawState tree_element_active_collection(
/* don't allow selecting a scene collection, it can have multiple layer collection
* instances (which one would the user want to be selected then?) */
else if (tselem->type == TSE_LAYER_COLLECTION) {
ViewLayer *view_layer = CTX_data_view_layer(C);
LayerCollection *lc = te->directdata;
const int collection_index = BKE_layer_collection_findindex(view_layer, lc);
LayerCollection *layer_collection = te->directdata;
/* If the collection is part of a group we don't change active collection. */
if (collection_index > -1) {
view_layer->active_collection = collection_index;
WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
switch (layer_collection->scene_collection->type) {
case COLLECTION_TYPE_NONE:
case COLLECTION_TYPE_GROUP_INTERNAL:
{
ViewLayer *view_layer = BKE_view_layer_find_from_collection(tselem->id, layer_collection);
const int collection_index = BKE_layer_collection_findindex(view_layer, layer_collection);
if (collection_index > -1) {
view_layer->active_collection = collection_index;
}
break;
}
default:
BLI_assert(!"Collection type not fully implemented");
}
WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
}
return OL_DRAWSEL_NONE;

View File

@ -126,7 +126,9 @@ typedef struct SpaceButs {
short preview; /* preview is signal to refresh */
/* texture context selector (material, lamp, particles, world, other) */
short texture_context, texture_context_prev;
char flag, pad[7];
char flag;
char collection_context;
char pad[6];
void *path; /* runtime */
int pathflag, dataicon; /* runtime */
@ -208,6 +210,12 @@ typedef enum eSpaceButtons_Texture_Context {
SB_TEXC_LINESTYLE = 5,
} eSpaceButtons_Texture_Context;
/* sbuts->collection_context */
typedef enum eSpaceButtons_Collection_Context {
SB_COLLECTION_CTX_VIEW_LAYER = 0,
SB_COLLECTION_CTX_GROUP = 1,
} eSpaceButtons_Collection_Context;
/* sbuts->align */
typedef enum eSpaceButtons_Align {
BUT_FREE = 0,

View File

@ -132,10 +132,11 @@ void RNA_def_group(BlenderRNA *brna)
RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_Group_objects_get", NULL, NULL, NULL, NULL);
rna_def_group_objects(brna, prop);
prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "view_layer->layer_collections", NULL);
RNA_def_property_struct_type(prop, "LayerCollection");
RNA_def_property_ui_text(prop, "Layer Collections", "");
prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "ViewLayer");
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "View Layer", "Group internal view layer");
}
#endif

View File

@ -225,6 +225,11 @@ static const EnumPropertyItem buttons_texture_context_items[] = {
{0, NULL, 0, NULL, NULL}
};
static const EnumPropertyItem buttons_collection_context_items[] = {
{SB_COLLECTION_CTX_VIEW_LAYER, "VIEW_LAYER", ICON_RENDERLAYERS, "", "Show material textures"},
{SB_COLLECTION_CTX_GROUP, "GROUP", ICON_GROUP, "", "Show world textures"},
{0, NULL, 0, NULL, NULL}
};
static const EnumPropertyItem fileselectparams_recursion_level_items[] = {
{0, "NONE", 0, "None", "Only list current directory's content, with no recursion"},
@ -2743,6 +2748,11 @@ static void rna_def_space_buttons(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Limited Texture Context",
"Use the limited version of texture user (for 'old shading' mode)");
prop = RNA_def_property(srna, "collection_context", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, buttons_collection_context_items);
RNA_def_property_ui_text(prop, "Collection Context", "Which collection we want to show");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL);
/* pinned data */
prop = RNA_def_property(srna, "pin_id", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "pinid");