Refactor: move ANIM_setting_get_rna_values to animrig #114444
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-FileCopyrightText: 2023 Blender Foundation
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup animrig
|
||||
*
|
||||
* \brief Helper functions for animation to interact with the RNA system.
|
||||
*/
|
||||
|
||||
#include "BLI_vector.hh"
|
||||
#include "RNA_types.hh"
|
||||
|
||||
namespace blender::animrig {
|
||||
|
||||
/** Get the values of the given property. Casts non-float properties to float. */
|
||||
Vector<float> ANIM_setting_get_rna_values(PointerRNA *ptr, PropertyRNA *prop);
|
||||
|
||||
} // namespace blender::animrig
|
|
@ -20,6 +20,7 @@ set(INC_SYS
|
|||
)
|
||||
|
||||
set(SRC
|
||||
intern/anim_rna.cc
|
||||
intern/bone_collections.cc
|
||||
intern/bonecolor.cc
|
||||
intern/fcurve.cc
|
||||
|
@ -33,6 +34,7 @@ set(SRC
|
|||
ANIM_bonecolor.hh
|
||||
ANIM_fcurve.hh
|
||||
ANIM_keyframing.hh
|
||||
ANIM_rna.hh
|
||||
ANIM_visualkey.hh
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
#include "BLI_vector.hh"
|
||||
#include "RNA_access.hh"
|
||||
#include "RNA_define.hh"
|
||||
#include "RNA_path.hh"
|
||||
#include "RNA_types.hh"
|
||||
|
||||
namespace blender::animrig {
|
||||
|
||||
Vector<float> ANIM_setting_get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
Vector<float> values;
|
||||
if (RNA_property_array_check(prop)) {
|
||||
const int length = RNA_property_array_length(ptr, prop);
|
||||
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_BOOLEAN: {
|
||||
bool *tmp_bool = static_cast<bool *>(MEM_malloc_arrayN(length, sizeof(bool), __func__));
|
||||
RNA_property_boolean_get_array(ptr, prop, tmp_bool);
|
||||
for (int i = 0; i < length; i++) {
|
||||
values.append(float(tmp_bool[i]));
|
||||
}
|
||||
MEM_freeN(tmp_bool);
|
||||
break;
|
||||
}
|
||||
case PROP_INT: {
|
||||
int *tmp_int = static_cast<int *>(MEM_malloc_arrayN(length, sizeof(int), __func__));
|
||||
RNA_property_int_get_array(ptr, prop, tmp_int);
|
||||
for (int i = 0; i < length; i++) {
|
||||
values.append(float(tmp_int[i]));
|
||||
}
|
||||
MEM_freeN(tmp_int);
|
||||
break;
|
||||
}
|
||||
case PROP_FLOAT: {
|
||||
values.reinitialize(length);
|
||||
RNA_property_float_get_array(ptr, prop, &values[0]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
values.reinitialize(length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_BOOLEAN:
|
||||
values.append(float(RNA_property_boolean_get(ptr, prop)));
|
||||
break;
|
||||
case PROP_INT:
|
||||
values.append(float(RNA_property_int_get(ptr, prop)));
|
||||
break;
|
||||
case PROP_FLOAT:
|
||||
values.append(RNA_property_float_get(ptr, prop));
|
||||
break;
|
||||
case PROP_ENUM:
|
||||
values.append(float(RNA_property_enum_get(ptr, prop)));
|
||||
break;
|
||||
default:
|
||||
values.append(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
} // namespace blender::animrig
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "ANIM_fcurve.hh"
|
||||
#include "ANIM_keyframing.hh"
|
||||
#include "ANIM_rna.hh"
|
||||
#include "ANIM_visualkey.hh"
|
||||
|
||||
#include "BKE_action.h"
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "ANIM_rna.hh"
|
||||
#include "ANIM_visualkey.hh"
|
||||
|
||||
#include "BKE_animsys.h"
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "ANIM_bone_collections.h"
|
||||
#include "ANIM_fcurve.hh"
|
||||
#include "ANIM_keyframing.hh"
|
||||
#include "ANIM_rna.hh"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
#include "UI_resources.hh"
|
||||
|
@ -554,66 +555,6 @@ int insert_vert_fcurve(
|
|||
return a;
|
||||
}
|
||||
|
||||
/* ------------------ RNA Data-Access Functions ------------------ */
|
||||
|
||||
/** Try to read value using RNA-properties obtained already. */
|
||||
blender::Vector<float> ANIM_setting_get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
blender::Vector<float> values;
|
||||
if (RNA_property_array_check(prop)) {
|
||||
const int length = RNA_property_array_length(ptr, prop);
|
||||
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_BOOLEAN: {
|
||||
bool *tmp_bool = static_cast<bool *>(MEM_malloc_arrayN(length, sizeof(bool), __func__));
|
||||
RNA_property_boolean_get_array(ptr, prop, tmp_bool);
|
||||
for (int i = 0; i < length; i++) {
|
||||
values.append(float(tmp_bool[i]));
|
||||
}
|
||||
MEM_freeN(tmp_bool);
|
||||
break;
|
||||
}
|
||||
case PROP_INT: {
|
||||
int *tmp_int = static_cast<int *>(MEM_malloc_arrayN(length, sizeof(int), __func__));
|
||||
RNA_property_int_get_array(ptr, prop, tmp_int);
|
||||
for (int i = 0; i < length; i++) {
|
||||
values.append(float(tmp_int[i]));
|
||||
}
|
||||
MEM_freeN(tmp_int);
|
||||
break;
|
||||
}
|
||||
case PROP_FLOAT: {
|
||||
values.reinitialize(length);
|
||||
RNA_property_float_get_array(ptr, prop, &values[0]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
values.reinitialize(length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_BOOLEAN:
|
||||
values.append(float(RNA_property_boolean_get(ptr, prop)));
|
||||
break;
|
||||
case PROP_INT:
|
||||
values.append(float(RNA_property_int_get(ptr, prop)));
|
||||
break;
|
||||
case PROP_FLOAT:
|
||||
values.append(RNA_property_float_get(ptr, prop));
|
||||
break;
|
||||
case PROP_ENUM:
|
||||
values.append(float(RNA_property_enum_get(ptr, prop)));
|
||||
break;
|
||||
default:
|
||||
values.append(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
/* ------------------------- Insert Key API ------------------------- */
|
||||
|
||||
void ED_keyframes_add(FCurve *fcu, int num_keys_to_add)
|
||||
|
@ -1613,7 +1554,7 @@ bool fcurve_is_changed(PointerRNA ptr,
|
|||
anim_rna.prop_index = fcu->array_index;
|
||||
|
||||
int index = fcu->array_index;
|
||||
blender::Vector<float> values = ANIM_setting_get_rna_values(&ptr, prop);
|
||||
blender::Vector<float> values = blender::animrig::ANIM_setting_get_rna_values(&ptr, prop);
|
||||
|
||||
float fcurve_val = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
|
||||
float cur_val = (index >= 0 && index < values.size()) ? values[index] : 0.0f;
|
||||
|
|
|
@ -39,8 +39,6 @@ struct NlaKeyframingContext;
|
|||
/** \name Key-Framing Management
|
||||
* \{ */
|
||||
|
||||
blender::Vector<float> ANIM_setting_get_rna_values(PointerRNA *ptr, PropertyRNA *prop);
|
||||
|
||||
/**
|
||||
* Get the active settings for key-framing settings from context (specifically the given scene)
|
||||
* \param use_autokey_mode: include settings from key-framing mode in the result
|
||||
|
|
Loading…
Reference in New Issue