Fix #98923 : Remove the ability to offset a linked collection asset not instantiated #104958

Open
Colin Marmond wants to merge 2 commits from Kdaf/blender:fix-98923-collection-asset-instance-offset_ into blender-v3.5-release

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 24 additions and 1 deletions

View File

@ -1831,7 +1831,7 @@ static int collection_drop_exec(bContext *C, wmOperator *op)
ob->transflag |= OB_DUPLICOLLECTION;
id_us_plus(&add_info->collection->id);
}
else {
else if (!ID_IS_LINKED(&add_info->collection->id)) {
ViewLayer *view_layer = CTX_data_view_layer(C);
float delta_mat[4][4];
unit_m4(delta_mat);
@ -1857,6 +1857,28 @@ static int collection_drop_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
/* Disable location and rotation controls for the user when the collection
* is linked and not instantiated */
static bool collection_drop_poll_property(const bContext *C,
wmOperator *op,
const PropertyRNA *prop)
{
if (RNA_boolean_get(op->ptr, "use_instance"))
Review
Style: Always use braces https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Braces
return true;
const char *prop_name = RNA_property_ui_name(prop);
Review

This shouldn't use the UI name but the internal identifier, see RNA_property_identifier(). UI names are supposed to be changeable without compatibility concerns, plus they are translated. For example this code will break for languages that have "Rotation" or "Location" translated.

This shouldn't use the UI name but the internal identifier, see `RNA_property_identifier()`. UI names are supposed to be changeable without compatibility concerns, plus they are translated. For example this code will break for languages that have "Rotation" or "Location" translated.
if (STR_ELEM(prop_name, "Location", "Rotation")) {
Collection *collection = static_cast<Collection *>(
BLI_findlink(&CTX_data_main(C)->collections, RNA_enum_get(op->ptr, "collection")));
Review

This is not in sync with how collection_drop_exec() gets the collection, that first attempts to get the collection from the session UUID and the name, see collection_add_info_get_from_op().

This is not in sync with how `collection_drop_exec()` gets the collection, that first attempts to get the collection from the session UUID and the name, see `collection_add_info_get_from_op()`.
if (!ID_IS_LINKED(&collection->id))
Review

I'd omit the negation to make this more readable / less error-prone:

if (ID_IS_LINKED(&collection->id)) {
  return false;
}
return true;
I'd omit the negation to make this more readable / less error-prone: ``` if (ID_IS_LINKED(&collection->id)) { return false; } return true; ```
return true;
return false;
}
return true;
}
void OBJECT_OT_collection_external_asset_drop(wmOperatorType *ot)
{
PropertyRNA *prop;
@ -1871,6 +1893,7 @@ void OBJECT_OT_collection_external_asset_drop(wmOperatorType *ot)
ot->invoke = object_instance_add_invoke;
ot->exec = collection_drop_exec;
ot->poll = ED_operator_objectmode;
ot->poll_property = collection_drop_poll_property;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;