Viewport: cannot select object by clicking on its instances

Selecting an object by clicking on its instances only worked,
when the object itself is visible. However, it is possible to hide
the object and still keep the instances visible.

The solution is to give every object the correct `select_id` in the
depsgraph object iterator right before rendering.

Reviewers: fclem, brecht

Differential Revision: https://developer.blender.org/D9640
This commit is contained in:
Jacques Lucke 2020-11-24 17:32:40 +01:00
parent 256a9d983d
commit e922dd7d8a
6 changed files with 11 additions and 13 deletions

View File

@ -154,6 +154,7 @@ bool deg_objects_dupli_iterator_next(BLI_Iterator *iter)
dupli_parent->runtime.local_collections_bits;
temp_dupli_object->dt = MIN2(temp_dupli_object->dt, dupli_parent->dt);
copy_v4_v4(temp_dupli_object->color, dupli_parent->color);
temp_dupli_object->runtime.select_id = dupli_parent->runtime.select_id;
/* Duplicated elements shouldn't care whether their original collection is visible or not. */
temp_dupli_object->base_flag |= BASE_VISIBLE_DEPSGRAPH;
@ -224,6 +225,7 @@ void deg_iterator_objects_step(BLI_Iterator *iter, deg::IDNode *id_node)
}
}
object->runtime.select_id = DEG_get_original_object(object)->runtime.select_id;
if (ob_visibility & OB_VISIBLE_INSTANCES) {
if ((data->flag & DEG_ITER_OBJECT_FLAG_DUPLI) && (object->transflag & OB_DUPLI)) {
data->dupli_parent = object;

View File

@ -1910,7 +1910,7 @@ static void draw_armature_edit(ArmatureDrawContext *ctx)
edbo_compute_bbone_child(arm);
for (eBone = arm->edbo->first, index = ob_orig->runtime.select_id; eBone;
for (eBone = arm->edbo->first, index = ob->runtime.select_id; eBone;
eBone = eBone->next, index += 0x10000) {
if (eBone->layer & arm->layer) {
if ((eBone->flag & BONE_HIDDEN_A) == 0) {
@ -2005,8 +2005,7 @@ static void draw_armature_pose(ArmatureDrawContext *ctx)
DRW_state_is_select();
if (is_pose_select) {
const Object *ob_orig = DEG_get_original_object(ob);
index = ob_orig->runtime.select_id;
index = ob->runtime.select_id;
}
}

View File

@ -871,7 +871,6 @@ static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb,
{
const DRWContextState *draw_ctx = DRW_context_state_get();
const bool is_select = DRW_state_is_select();
const Object *orig_camera_object = DEG_get_original_object(camera_object);
MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
if (clip == NULL) {
@ -945,7 +944,7 @@ static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb,
}
if (is_select) {
DRW_select_load_id(orig_camera_object->runtime.select_id | (track_index << 16));
DRW_select_load_id(camera_object->runtime.select_id | (track_index << 16));
track_index++;
}

View File

@ -82,8 +82,7 @@ void OVERLAY_edit_metaball_cache_populate(OVERLAY_Data *vedata, Object *ob)
int select_id = 0;
if (is_select) {
const Object *orig_object = DEG_get_original_object(ob);
select_id = orig_object->runtime.select_id;
select_id = ob->runtime.select_id;
}
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {

View File

@ -2422,11 +2422,7 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
}
}
/* This relies on dupli instances being after their instancing object. */
if ((ob->base_flag & BASE_FROM_DUPLI) == 0) {
Object *ob_orig = DEG_get_original_object(ob);
DRW_select_load_id(ob_orig->runtime.select_id);
}
DRW_select_load_id(ob->runtime.select_id);
DST.dupli_parent = data_.dupli_parent;
DST.dupli_source = data_.dupli_object_current;
drw_duplidata_load(DST.dupli_source);

View File

@ -126,7 +126,10 @@ typedef struct Object_Runtime {
/** Only used for drawing the parent/child help-line. */
float parent_display_origin[3];
/** Selection id of this object; only available in the original object */
/**
* Selection id of this object. It might differ between an evaluated and its original object,
* when the object is being instanced.
*/
int select_id;
char _pad1[3];