Merge branch 'blender-v3.6-release'

This commit is contained in:
Nathan Vegdahl
2023-06-06 11:14:50 +02:00
4 changed files with 127 additions and 38 deletions

View File

@@ -58,6 +58,11 @@ struct AnimData *BKE_animdata_ensure_id(struct ID *id);
*/
bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct bAction *act);
/**
* Same as BKE_animdata_set_action(), except sets `tmpact` instead of `action`.
*/
bool BKE_animdata_set_tmpact(struct ReportList *reports, struct ID *id, struct bAction *act);
bool BKE_animdata_action_editable(const struct AnimData *adt);
/**

View File

@@ -114,39 +114,23 @@ AnimData *BKE_animdata_ensure_id(ID *id)
return NULL;
}
/* Action Setter --------------------------------------- */
bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
/* Action / Tmpact Setter shared code -------------------------
*
* Both the action and tmpact setter functions have essentially
* identical semantics, because tmpact is just a place to temporarily
* store the main action during tweaking. This function contains the
* shared code between those two setter functions, setting the action
* of the passed `act_slot` to `act`.
*
* Preconditions:
* - `id` and `act_slot` must be non-null (but the pointer `act_slot`
* points to can be null).
* - `id` must have animation data.
* - `act_slot` must be a pointer to either the `action` or `tmpact`
* field of `id`'s animation data.
*/
static bool animdata_set_action(ReportList *reports, ID *id, bAction **act_slot, bAction *act)
{
AnimData *adt = BKE_animdata_from_id(id);
/* Animdata validity check. */
if (adt == NULL) {
BKE_report(reports, RPT_WARNING, "No AnimData to set action on");
return false;
}
if (adt->action == act) {
/* Don't bother reducing and increasing the user count when there is nothing changing. */
return true;
}
if (!BKE_animdata_action_editable(adt)) {
/* Cannot remove, otherwise things turn to custard. */
BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA");
return false;
}
/* Unassign current action. */
if (adt->action) {
id_us_min((ID *)adt->action);
adt->action = NULL;
}
if (act == NULL) {
return true;
}
/* Action must have same type as owner. */
if (!BKE_animdata_action_ensure_idroot(id, act)) {
/* Cannot set to this type. */
@@ -160,12 +144,59 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
return false;
}
adt->action = act;
id_us_plus((ID *)adt->action);
if (*act_slot == act) {
/* Don't bother reducing and increasing the user count when there is nothing changing. */
return true;
}
/* Unassign current action. */
if (*act_slot) {
id_us_min((ID *)*act_slot);
*act_slot = NULL;
}
if (act == NULL) {
return true;
}
*act_slot = act;
id_us_plus((ID *)*act_slot);
return true;
}
/* Tmpact Setter --------------------------------------- */
bool BKE_animdata_set_tmpact(ReportList *reports, ID *id, bAction *act)
{
AnimData *adt = BKE_animdata_from_id(id);
if (adt == NULL) {
BKE_report(reports, RPT_WARNING, "No AnimData to set tmpact on");
return false;
}
return animdata_set_action(reports, id, &adt->tmpact, act);
}
/* Action Setter --------------------------------------- */
bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
{
AnimData *adt = BKE_animdata_from_id(id);
if (adt == NULL) {
BKE_report(reports, RPT_WARNING, "No AnimData to set action on");
return false;
}
if (!BKE_animdata_action_editable(adt)) {
/* Cannot remove, otherwise things turn to custard. */
BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA");
return false;
}
return animdata_set_action(reports, id, &adt->action, act);
}
bool BKE_animdata_action_editable(const AnimData *adt)
{
/* Active action is only editable when it is not a tweaking strip. */

View File

@@ -6628,9 +6628,12 @@ static void default_paint_slot_color_get(int layer_type, Material *ma, float col
case LAYER_ROUGHNESS:
case LAYER_METALLIC: {
bNodeTree *ntree = nullptr;
ma->nodetree->ensure_topology_cache();
const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
bNode *in_node = nodes.is_empty() ? nullptr : nodes.first();
bNode *in_node = nullptr;
if (ma && ma->nodetree) {
ma->nodetree->ensure_topology_cache();
const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
in_node = nodes.is_empty() ? nullptr : nodes.first();
}
if (!in_node) {
/* An existing material or Principled BSDF node could not be found.
* Copy default color values from a default Principled BSDF instead. */
@@ -6861,7 +6864,8 @@ static int texture_paint_add_texture_paint_slot_invoke(bContext *C,
get_default_texture_layer_name_for_object(ob, type, (char *)&imagename, sizeof(imagename));
RNA_string_set(op->ptr, "name", imagename);
/* Set default color. Copy the color from nodes, so it matches the existing material. */
/* Set default color. Copy the color from nodes, so it matches the existing material.
* Material could be null so we should have a default color. */
float color[4];
default_paint_slot_color_get(type, ma, color);
RNA_float_set_array(op->ptr, "color", color);

View File

@@ -145,6 +145,16 @@ static void rna_AnimData_action_set(PointerRNA *ptr,
BKE_animdata_set_action(NULL, ownerId, value.data);
}
static void rna_AnimData_tmpact_set(PointerRNA *ptr,
PointerRNA value,
struct ReportList *UNUSED(reports))
{
ID *ownerId = ptr->owner_id;
/* set action */
BKE_animdata_set_tmpact(NULL, ownerId, value.data);
}
static void rna_AnimData_tweakmode_set(PointerRNA *ptr, const bool value)
{
AnimData *adt = (AnimData *)ptr->data;
@@ -162,6 +172,34 @@ static void rna_AnimData_tweakmode_set(PointerRNA *ptr, const bool value)
}
}
/* This is used to avoid the check for NLA tracks when enabling tweak
* mode while loading overrides. This is necessary because the normal
* RNA tweak-mode setter refuses to enable tweak mode if there are no
* NLA tracks since that's normally an invalid state... but the
* overriden NLA tracks are only added *after* setting the tweak mode
* override. */
bool rna_AnimData_tweakmode_override_apply(Main *UNUSED(bmain),
PointerRNA *ptr_dst,
PointerRNA *ptr_src,
PointerRNA *UNUSED(ptr_storage),
PropertyRNA *UNUSED(prop_dst),
PropertyRNA *UNUSED(prop_src),
PropertyRNA *UNUSED(prop_storage),
const int UNUSED(len_dst),
const int UNUSED(len_src),
const int UNUSED(len_storage),
PointerRNA *UNUSED(ptr_item_dst),
PointerRNA *UNUSED(ptr_item_src),
PointerRNA *UNUSED(ptr_item_storage),
IDOverrideLibraryPropertyOperation *UNUSED(opop))
{
AnimData *anim_data_dst = (AnimData *)ptr_dst->data;
AnimData *anim_data_src = (AnimData *)ptr_src->data;
anim_data_dst->flag =(anim_data_dst->flag & ~ADT_NLA_EDIT_ON) | (anim_data_src->flag & ADT_NLA_EDIT_ON);
return true;
}
/* ****************************** */
/* wrapper for poll callback */
@@ -1372,6 +1410,16 @@ static void rna_def_animdata(BlenderRNA *brna)
"Amount the Active Action contributes to the result of the NLA stack");
RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, "rna_AnimData_update"); /* this will do? */
/* Temporary action slot for tweak mode. */
prop = RNA_def_property(srna, "action_tweak_storage", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "tmpact");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_pointer_funcs(
prop, NULL, "rna_AnimData_tmpact_set", NULL, "rna_Action_id_poll");
RNA_def_property_ui_text(
prop, "Tweak Mode Action Storage", "Slot to temporarily hold the main action while in tweak mode");
RNA_def_property_update(prop, NC_ANIMATION | ND_NLA_ACTCHANGE, "rna_AnimData_dependency_update");
/* Drivers */
prop = RNA_def_property(srna, "drivers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "drivers", NULL);
@@ -1397,6 +1445,7 @@ static void rna_def_animdata(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "Use NLA Tweak Mode", "Whether to enable or disable tweak mode in NLA");
RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, "rna_AnimData_update");
RNA_def_property_override_funcs(prop, NULL, NULL, "rna_AnimData_tweakmode_override_apply");
prop = RNA_def_property(srna, "use_pin", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);