2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-03 21:18:10 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-03 21:18:10 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup RNA
|
2011-02-27 20:20:01 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-12-03 21:18:10 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2008-12-04 00:07:47 +00:00
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
#include "DNA_curve_types.h"
|
2008-12-03 21:18:10 +00:00
|
|
|
#include "DNA_key_types.h"
|
2008-12-04 00:07:47 +00:00
|
|
|
#include "DNA_lattice_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_scene_types.h"
|
2008-12-03 21:18:10 +00:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
#include "BLI_math.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2013-03-07 02:44:55 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-25 08:29:06 +00:00
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
2013-09-11 21:27:14 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2013-03-07 02:44:55 +00:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "rna_internal.h"
|
|
|
|
|
|
2008-12-03 21:18:10 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
2008-12-04 00:07:47 +00:00
|
|
|
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
# include <stddef.h>
|
|
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
# include "DNA_object_types.h"
|
|
|
|
|
|
2020-04-03 17:38:58 +02:00
|
|
|
# include "BLI_listbase.h"
|
2019-01-26 20:41:52 +11:00
|
|
|
# include "BLI_string_utils.h"
|
|
|
|
|
|
2009-10-20 04:07:57 +00:00
|
|
|
# include "BKE_animsys.h"
|
2009-07-03 15:23:33 +00:00
|
|
|
# include "BKE_key.h"
|
|
|
|
|
# include "BKE_main.h"
|
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
# include "DEG_depsgraph.h"
|
|
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
# include "WM_api.h"
|
|
|
|
|
# include "WM_types.h"
|
|
|
|
|
|
2009-10-22 23:23:09 +00:00
|
|
|
static Key *rna_ShapeKey_find_key(ID *id)
|
|
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
switch (GS(id->name)) {
|
2012-05-12 11:01:29 +00:00
|
|
|
case ID_CU:
|
|
|
|
|
return ((Curve *)id)->key;
|
|
|
|
|
case ID_KE:
|
|
|
|
|
return (Key *)id;
|
|
|
|
|
case ID_LT:
|
|
|
|
|
return ((Lattice *)id)->key;
|
|
|
|
|
case ID_ME:
|
|
|
|
|
return ((Mesh *)id)->key;
|
2012-09-19 10:12:07 +00:00
|
|
|
case ID_OB:
|
|
|
|
|
return BKE_key_from_object((Object *)id);
|
2009-10-22 23:23:09 +00:00
|
|
|
default:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-22 14:07:55 +00:00
|
|
|
static void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
KeyBlock *kb = ptr->data;
|
2010-04-04 14:33:41 +00:00
|
|
|
char oldname[sizeof(kb->name)];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
/* make a copy of the old name first */
|
2010-04-04 14:33:41 +00:00
|
|
|
BLI_strncpy(oldname, kb->name, sizeof(kb->name));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
/* copy the new name into the name slot */
|
2011-09-15 12:26:48 +00:00
|
|
|
BLI_strncpy_utf8(kb->name, value, sizeof(kb->name));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
/* make sure the name is truly unique */
|
2019-08-23 09:52:12 +02:00
|
|
|
if (ptr->owner_id) {
|
|
|
|
|
Key *key = rna_ShapeKey_find_key(ptr->owner_id);
|
2015-08-16 17:32:01 +10:00
|
|
|
BLI_uniquename(&key->block,
|
|
|
|
|
kb,
|
|
|
|
|
CTX_DATA_(BLT_I18NCONTEXT_ID_SHAPEKEY, "Key"),
|
|
|
|
|
'.',
|
2013-03-25 08:29:06 +00:00
|
|
|
offsetof(KeyBlock, name),
|
|
|
|
|
sizeof(kb->name));
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
/* fix all the animation data which may link to this */
|
2015-04-04 15:13:56 +11:00
|
|
|
BKE_animdata_fix_paths_rename_all(NULL, "key_blocks", oldname, kb->name);
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
static float rna_ShapeKey_frame_get(PointerRNA *ptr)
|
|
|
|
|
{
|
|
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
|
|
|
|
return kb->pos * 100.0f; /* Because pos is ctime/100... */
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-01 06:03:08 +00:00
|
|
|
static void rna_ShapeKey_value_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *data = (KeyBlock *)ptr->data;
|
2009-08-01 06:03:08 +00:00
|
|
|
CLAMP(value, data->slidermin, data->slidermax);
|
2012-03-05 23:30:41 +00:00
|
|
|
data->curval = value;
|
2009-08-01 06:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-20 06:35:28 +00:00
|
|
|
static void rna_ShapeKey_value_range(
|
|
|
|
|
PointerRNA *ptr, float *min, float *max, float *UNUSED(softmin), float *UNUSED(softmax))
|
2009-08-01 06:03:08 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *data = (KeyBlock *)ptr->data;
|
2009-08-01 06:03:08 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
*min = data->slidermin;
|
|
|
|
|
*max = data->slidermax;
|
2009-08-01 06:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-03 11:58:19 +00:00
|
|
|
/* epsilon for how close one end of shapekey range can get to the other */
|
2011-03-28 02:34:55 +00:00
|
|
|
# define SHAPEKEY_SLIDER_TOL 0.001f
|
2011-01-03 11:58:19 +00:00
|
|
|
|
2013-09-20 06:35:28 +00:00
|
|
|
static void rna_ShapeKey_slider_min_range(
|
|
|
|
|
PointerRNA *ptr, float *min, float *max, float *UNUSED(softmin), float *UNUSED(softmax))
|
2011-01-03 11:58:19 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *data = (KeyBlock *)ptr->data;
|
2011-01-03 11:58:19 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
*min = -10.0f;
|
|
|
|
|
*max = data->slidermax - SHAPEKEY_SLIDER_TOL;
|
2011-01-03 11:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKey_slider_min_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *data = (KeyBlock *)ptr->data;
|
2012-03-30 16:09:05 +00:00
|
|
|
float min, max, softmin, softmax;
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2012-03-30 16:09:05 +00:00
|
|
|
rna_ShapeKey_slider_min_range(ptr, &min, &max, &softmin, &softmax);
|
2011-01-03 11:58:19 +00:00
|
|
|
CLAMP(value, min, max);
|
|
|
|
|
data->slidermin = value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 06:35:28 +00:00
|
|
|
static void rna_ShapeKey_slider_max_range(
|
|
|
|
|
PointerRNA *ptr, float *min, float *max, float *UNUSED(softmin), float *UNUSED(softmax))
|
2011-01-03 11:58:19 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *data = (KeyBlock *)ptr->data;
|
2011-01-03 11:58:19 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
*min = data->slidermin + SHAPEKEY_SLIDER_TOL;
|
|
|
|
|
*max = 10.0f;
|
2011-01-03 11:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKey_slider_max_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *data = (KeyBlock *)ptr->data;
|
2012-03-30 16:09:05 +00:00
|
|
|
float min, max, softmin, softmax;
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2012-03-30 16:09:05 +00:00
|
|
|
rna_ShapeKey_slider_max_range(ptr, &min, &max, &softmin, &softmax);
|
2011-01-03 11:58:19 +00:00
|
|
|
CLAMP(value, min, max);
|
|
|
|
|
data->slidermax = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# undef SHAPEKEY_SLIDER_TOL
|
|
|
|
|
|
2015-10-12 20:12:55 +02:00
|
|
|
/* ***** Normals accessors for shapekeys. ***** */
|
2019-04-22 02:48:05 +10:00
|
|
|
/* Note: with this we may recompute several times the same data, should we want to access verts,
|
|
|
|
|
* then polys, then loops normals... However,
|
|
|
|
|
* such case looks rather unlikely - and not worth adding some kind of caching in KeyBlocks.
|
2015-10-12 20:12:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static Mesh *rna_KeyBlock_normals_get_mesh(PointerRNA *ptr, ID *id)
|
|
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
Key *key = rna_ShapeKey_find_key((id == NULL && ptr != NULL) ? ptr->owner_id : id);
|
2015-10-12 20:12:55 +02:00
|
|
|
id = key ? key->from : NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-12 20:12:55 +02:00
|
|
|
if (id != NULL) {
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
|
case ID_ME:
|
|
|
|
|
return (Mesh *)id;
|
|
|
|
|
case ID_OB: {
|
|
|
|
|
Object *ob = (Object *)id;
|
|
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
|
return ob->data;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-28 11:19:58 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2015-10-12 20:12:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-12 20:12:55 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_KeyBlock_normals_vert_len(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
|
|
|
|
|
{
|
|
|
|
|
Mesh *me = rna_KeyBlock_normals_get_mesh(ptr, NULL);
|
|
|
|
|
|
|
|
|
|
length[0] = me ? me->totvert : 0;
|
|
|
|
|
length[1] = 3;
|
|
|
|
|
|
|
|
|
|
return (length[0] * length[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_KeyBlock_normals_vert_calc(ID *id,
|
|
|
|
|
KeyBlock *data,
|
|
|
|
|
int *normals_len,
|
|
|
|
|
float **normals)
|
|
|
|
|
{
|
|
|
|
|
Mesh *me = rna_KeyBlock_normals_get_mesh(NULL, id);
|
|
|
|
|
|
|
|
|
|
*normals_len = (me ? me->totvert : 0) * 3;
|
|
|
|
|
|
|
|
|
|
if (ELEM(NULL, me, data) || (me->totvert == 0)) {
|
|
|
|
|
*normals = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*normals = MEM_mallocN(sizeof(**normals) * (size_t)(*normals_len), __func__);
|
|
|
|
|
|
|
|
|
|
BKE_keyblock_mesh_calc_normals(data, me, (float(*)[3])(*normals), NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_KeyBlock_normals_poly_len(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
|
|
|
|
|
{
|
|
|
|
|
Mesh *me = rna_KeyBlock_normals_get_mesh(ptr, NULL);
|
|
|
|
|
|
|
|
|
|
length[0] = me ? me->totpoly : 0;
|
|
|
|
|
length[1] = 3;
|
|
|
|
|
|
|
|
|
|
return (length[0] * length[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_KeyBlock_normals_poly_calc(ID *id,
|
|
|
|
|
KeyBlock *data,
|
|
|
|
|
int *normals_len,
|
|
|
|
|
float **normals)
|
|
|
|
|
{
|
|
|
|
|
Mesh *me = rna_KeyBlock_normals_get_mesh(NULL, id);
|
|
|
|
|
|
|
|
|
|
*normals_len = (me ? me->totpoly : 0) * 3;
|
|
|
|
|
|
|
|
|
|
if (ELEM(NULL, me, data) || (me->totpoly == 0)) {
|
|
|
|
|
*normals = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*normals = MEM_mallocN(sizeof(**normals) * (size_t)(*normals_len), __func__);
|
|
|
|
|
|
|
|
|
|
BKE_keyblock_mesh_calc_normals(data, me, NULL, (float(*)[3])(*normals), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_KeyBlock_normals_loop_len(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
|
|
|
|
|
{
|
|
|
|
|
Mesh *me = rna_KeyBlock_normals_get_mesh(ptr, NULL);
|
|
|
|
|
|
|
|
|
|
length[0] = me ? me->totloop : 0;
|
|
|
|
|
length[1] = 3;
|
|
|
|
|
|
|
|
|
|
return (length[0] * length[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_KeyBlock_normals_loop_calc(ID *id,
|
|
|
|
|
KeyBlock *data,
|
|
|
|
|
int *normals_len,
|
|
|
|
|
float **normals)
|
|
|
|
|
{
|
|
|
|
|
Mesh *me = rna_KeyBlock_normals_get_mesh(NULL, id);
|
|
|
|
|
|
|
|
|
|
*normals_len = (me ? me->totloop : 0) * 3;
|
|
|
|
|
|
|
|
|
|
if (ELEM(NULL, me, data) || (me->totloop == 0)) {
|
|
|
|
|
*normals = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*normals = MEM_mallocN(sizeof(**normals) * (size_t)(*normals_len), __func__);
|
|
|
|
|
|
|
|
|
|
BKE_keyblock_mesh_calc_normals(data, me, NULL, NULL, (float(*)[3])(*normals));
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 11:49:07 +00:00
|
|
|
PointerRNA rna_object_shapekey_index_get(ID *id, int value)
|
2008-12-04 00:07:47 +00:00
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
Key *key = rna_ShapeKey_find_key(id);
|
|
|
|
|
KeyBlock *kb = NULL;
|
2010-03-30 11:49:07 +00:00
|
|
|
PointerRNA ptr;
|
2008-12-04 00:07:47 +00:00
|
|
|
|
2019-06-04 00:21:57 +10:00
|
|
|
if (key && value < key->totkey) {
|
2011-01-26 10:46:43 +00:00
|
|
|
kb = BLI_findlink(&key->block, value);
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2010-03-30 11:49:07 +00:00
|
|
|
RNA_pointer_create(id, &RNA_ShapeKey, kb, &ptr);
|
2008-12-04 00:07:47 +00:00
|
|
|
|
2010-03-30 11:49:07 +00:00
|
|
|
return ptr;
|
2008-12-04 00:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 11:49:07 +00:00
|
|
|
int rna_object_shapekey_index_set(ID *id, PointerRNA value, int current)
|
2009-07-03 15:23:33 +00:00
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
Key *key = rna_ShapeKey_find_key(id);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2011-01-26 10:46:43 +00:00
|
|
|
if (key) {
|
|
|
|
|
int a = BLI_findindex(&key->block, value.data);
|
2019-06-04 00:21:57 +10:00
|
|
|
if (a != -1) {
|
2014-02-01 01:45:09 +11:00
|
|
|
return a;
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
2011-01-26 10:46:43 +00:00
|
|
|
}
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2010-03-30 11:49:07 +00:00
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PointerRNA rna_ShapeKey_relative_key_get(PointerRNA *ptr)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
2010-03-30 11:49:07 +00:00
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
return rna_object_shapekey_index_get(ptr->owner_id, kb->relative);
|
2010-03-30 11:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 18:06:09 +10:00
|
|
|
static void rna_ShapeKey_relative_key_set(PointerRNA *ptr,
|
|
|
|
|
PointerRNA value,
|
|
|
|
|
struct ReportList *UNUSED(reports))
|
2010-03-30 11:49:07 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
2010-03-30 11:49:07 +00:00
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
kb->relative = rna_object_shapekey_index_set(ptr->owner_id, value, kb->relative);
|
2009-07-03 15:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyPoint_co_get(PointerRNA *ptr, float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
values[0] = vec[0];
|
|
|
|
|
values[1] = vec[1];
|
|
|
|
|
values[2] = vec[2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyPoint_co_set(PointerRNA *ptr, const float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
vec[0] = values[0];
|
|
|
|
|
vec[1] = values[1];
|
|
|
|
|
vec[2] = values[2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static float rna_ShapeKeyCurvePoint_tilt_get(PointerRNA *ptr)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2008-12-04 01:58:14 +00:00
|
|
|
return vec[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKeyCurvePoint_tilt_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2012-03-05 23:30:41 +00:00
|
|
|
vec[3] = value;
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
static float rna_ShapeKeyCurvePoint_radius_get(PointerRNA *ptr)
|
|
|
|
|
{
|
|
|
|
|
float *vec = (float *)ptr->data;
|
|
|
|
|
return vec[4];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKeyCurvePoint_radius_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
|
|
|
|
float *vec = (float *)ptr->data;
|
|
|
|
|
CLAMP_MIN(value, 0.0f);
|
|
|
|
|
vec[4] = value;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyBezierPoint_co_get(PointerRNA *ptr, float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-05-12 11:01:29 +00:00
|
|
|
values[0] = vec[0 + 3];
|
|
|
|
|
values[1] = vec[1 + 3];
|
|
|
|
|
values[2] = vec[2 + 3];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyBezierPoint_co_set(PointerRNA *ptr, const float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-05-12 11:01:29 +00:00
|
|
|
vec[0 + 3] = values[0];
|
|
|
|
|
vec[1 + 3] = values[1];
|
|
|
|
|
vec[2 + 3] = values[2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyBezierPoint_handle_1_co_get(PointerRNA *ptr, float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
values[0] = vec[0];
|
|
|
|
|
values[1] = vec[1];
|
|
|
|
|
values[2] = vec[2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyBezierPoint_handle_1_co_set(PointerRNA *ptr, const float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
vec[0] = values[0];
|
|
|
|
|
vec[1] = values[1];
|
|
|
|
|
vec[2] = values[2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyBezierPoint_handle_2_co_get(PointerRNA *ptr, float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-05-12 11:01:29 +00:00
|
|
|
values[0] = vec[6 + 0];
|
|
|
|
|
values[1] = vec[6 + 1];
|
|
|
|
|
values[2] = vec[6 + 2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static void rna_ShapeKeyBezierPoint_handle_2_co_set(PointerRNA *ptr, const float *values)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2009-02-02 19:57:57 +00:00
|
|
|
|
2012-05-12 11:01:29 +00:00
|
|
|
vec[6 + 0] = values[0];
|
|
|
|
|
vec[6 + 1] = values[1];
|
|
|
|
|
vec[6 + 2] = values[2];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-22 11:54:53 +00:00
|
|
|
static float rna_ShapeKeyBezierPoint_tilt_get(PointerRNA *ptr)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2018-12-05 18:30:42 +03:00
|
|
|
return vec[9];
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKeyBezierPoint_tilt_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
float *vec = (float *)ptr->data;
|
2018-12-05 18:30:42 +03:00
|
|
|
vec[9] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static float rna_ShapeKeyBezierPoint_radius_get(PointerRNA *ptr)
|
|
|
|
|
{
|
|
|
|
|
float *vec = (float *)ptr->data;
|
|
|
|
|
return vec[10];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKeyBezierPoint_radius_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
|
|
|
|
float *vec = (float *)ptr->data;
|
|
|
|
|
CLAMP_MIN(value, 0.0f);
|
2012-05-12 11:01:29 +00:00
|
|
|
vec[10] = value;
|
2012-04-22 11:54:53 +00:00
|
|
|
}
|
2018-12-05 18:30:42 +03:00
|
|
|
|
|
|
|
|
/* Indexing and iteration of Curve points through sub-curves. */
|
|
|
|
|
typedef struct NurbInfo {
|
|
|
|
|
Nurb *nu;
|
|
|
|
|
int nurb_size, nurb_elem_step;
|
|
|
|
|
|
|
|
|
|
/* Current index in the Nurb */
|
|
|
|
|
int nurb_index;
|
|
|
|
|
|
|
|
|
|
/* Total index as item and element. */
|
|
|
|
|
int item_index, elem_index;
|
|
|
|
|
} NurbInfo;
|
|
|
|
|
|
|
|
|
|
StructRNA *rna_ShapeKey_curve_point_type(Nurb *nu)
|
|
|
|
|
{
|
|
|
|
|
if (nu->bezt) {
|
|
|
|
|
return &RNA_ShapeKeyBezierPoint;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return &RNA_ShapeKeyCurvePoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKey_NurbInfo_init(NurbInfo *r_info, Nurb *nu)
|
|
|
|
|
{
|
|
|
|
|
r_info->nu = nu;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
if (nu->bezt) {
|
|
|
|
|
r_info->nurb_size = nu->pntsu;
|
|
|
|
|
r_info->nurb_elem_step = KEYELEM_ELEM_LEN_BEZTRIPLE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r_info->nurb_size = nu->pntsu * nu->pntsv;
|
|
|
|
|
r_info->nurb_elem_step = KEYELEM_ELEM_LEN_BPOINT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKey_NurbInfo_step(NurbInfo *r_info,
|
|
|
|
|
Nurb *nu,
|
|
|
|
|
int *p_raw_index,
|
|
|
|
|
bool input_elem)
|
|
|
|
|
{
|
|
|
|
|
rna_ShapeKey_NurbInfo_init(r_info, nu);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
if (input_elem) {
|
|
|
|
|
r_info->nurb_index = MIN2(r_info->nurb_size, *p_raw_index / r_info->nurb_elem_step);
|
|
|
|
|
*p_raw_index -= r_info->nurb_size * r_info->nurb_elem_step;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r_info->nurb_index = MIN2(r_info->nurb_size, *p_raw_index);
|
|
|
|
|
*p_raw_index -= r_info->nurb_size;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
r_info->item_index += r_info->nurb_index;
|
|
|
|
|
r_info->elem_index += r_info->nurb_index * r_info->nurb_elem_step;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_ShapeKey_NurbInfo_find_index(Key *key,
|
|
|
|
|
int raw_index,
|
|
|
|
|
bool input_elem,
|
|
|
|
|
NurbInfo *r_info)
|
|
|
|
|
{
|
|
|
|
|
Curve *cu = (Curve *)key->from;
|
|
|
|
|
|
|
|
|
|
memset(r_info, 0, sizeof(*r_info));
|
|
|
|
|
|
|
|
|
|
for (Nurb *nu = cu->nurb.first; nu && raw_index >= 0; nu = nu->next) {
|
|
|
|
|
rna_ShapeKey_NurbInfo_step(r_info, nu, &raw_index, input_elem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_ShapeKey_curve_find_index(Key *key, int elem_index)
|
|
|
|
|
{
|
|
|
|
|
NurbInfo info;
|
|
|
|
|
rna_ShapeKey_NurbInfo_find_index(key, elem_index, true, &info);
|
|
|
|
|
return info.item_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct ShapeKeyCurvePoint {
|
|
|
|
|
StructRNA *type;
|
|
|
|
|
void *data;
|
|
|
|
|
} ShapeKeyCurvePoint;
|
|
|
|
|
|
|
|
|
|
/* Build a mapping array for Curve objects with mixed sub-curve types. */
|
|
|
|
|
static void rna_ShapeKey_data_begin_mixed(CollectionPropertyIterator *iter,
|
|
|
|
|
Key *key,
|
|
|
|
|
KeyBlock *kb,
|
|
|
|
|
Curve *cu)
|
|
|
|
|
{
|
|
|
|
|
int point_count = rna_ShapeKey_curve_find_index(key, kb->totelem);
|
|
|
|
|
|
|
|
|
|
ShapeKeyCurvePoint *points = MEM_malloc_arrayN(
|
|
|
|
|
sizeof(ShapeKeyCurvePoint), point_count, __func__);
|
|
|
|
|
|
|
|
|
|
char *databuf = kb->data;
|
|
|
|
|
int items_left = point_count;
|
|
|
|
|
NurbInfo info = {NULL};
|
|
|
|
|
|
|
|
|
|
for (Nurb *nu = cu->nurb.first; nu && items_left > 0; nu = nu->next) {
|
|
|
|
|
ShapeKeyCurvePoint *nurb_points = points + info.item_index;
|
|
|
|
|
char *nurb_data = databuf + info.elem_index * key->elemsize;
|
|
|
|
|
|
|
|
|
|
rna_ShapeKey_NurbInfo_step(&info, nu, &items_left, false);
|
|
|
|
|
|
|
|
|
|
StructRNA *type = rna_ShapeKey_curve_point_type(nu);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < info.nurb_index; i++) {
|
|
|
|
|
nurb_points[i].type = type;
|
|
|
|
|
nurb_points[i].data = nurb_data + i * info.nurb_elem_step * key->elemsize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rna_iterator_array_begin(iter, points, sizeof(*points), point_count, true, NULL);
|
|
|
|
|
}
|
2008-12-04 01:58:14 +00:00
|
|
|
|
|
|
|
|
static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
|
|
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
Key *key = rna_ShapeKey_find_key(ptr->owner_id);
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
2012-03-05 23:30:41 +00:00
|
|
|
int tot = kb->totelem, size = key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
if (GS(key->from->name) == ID_CU && tot > 0) {
|
|
|
|
|
Curve *cu = (Curve *)key->from;
|
|
|
|
|
StructRNA *type = NULL;
|
|
|
|
|
NurbInfo info = {0};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
/* Check if all sub-curves have the same type. */
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
|
2018-12-05 18:30:42 +03:00
|
|
|
if (type == NULL) {
|
|
|
|
|
type = rna_ShapeKey_curve_point_type(nu);
|
|
|
|
|
rna_ShapeKey_NurbInfo_init(&info, nu);
|
|
|
|
|
}
|
|
|
|
|
else if (type != rna_ShapeKey_curve_point_type(nu)) {
|
|
|
|
|
type = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
/* If types are mixed, build a mapping array. */
|
|
|
|
|
if (type == NULL) {
|
|
|
|
|
rna_ShapeKey_data_begin_mixed(iter, key, kb, cu);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
tot /= info.nurb_elem_step;
|
|
|
|
|
size *= info.nurb_elem_step;
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-12 11:01:29 +00:00
|
|
|
rna_iterator_array_begin(iter, (void *)kb->data, size, tot, 0, NULL);
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_ShapeKey_data_length(PointerRNA *ptr)
|
|
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
Key *key = rna_ShapeKey_find_key(ptr->owner_id);
|
2012-05-12 11:01:29 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
2012-03-05 23:30:41 +00:00
|
|
|
int tot = kb->totelem;
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
if (GS(key->from->name) == ID_CU) {
|
2018-12-05 18:30:42 +03:00
|
|
|
tot = rna_ShapeKey_curve_find_index(key, tot);
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2008-12-04 01:58:14 +00:00
|
|
|
return tot;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-02 19:57:57 +00:00
|
|
|
static PointerRNA rna_ShapeKey_data_get(CollectionPropertyIterator *iter)
|
2008-12-04 01:58:14 +00:00
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
Key *key = rna_ShapeKey_find_key(iter->parent.owner_id);
|
2018-12-05 18:30:42 +03:00
|
|
|
void *ptr = rna_iterator_array_get(iter);
|
|
|
|
|
StructRNA *type = &RNA_ShapeKeyPoint;
|
|
|
|
|
|
|
|
|
|
/* If data_begin allocated a mapping array, access it. */
|
|
|
|
|
if (iter->internal.array.free_ptr) {
|
|
|
|
|
ShapeKeyCurvePoint *point = ptr;
|
|
|
|
|
|
|
|
|
|
return rna_pointer_inherit_refine(&iter->parent, point->type, point->data);
|
|
|
|
|
}
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
if (GS(key->from->name) == ID_CU) {
|
2018-12-05 18:30:42 +03:00
|
|
|
Curve *cu = (Curve *)key->from;
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
type = rna_ShapeKey_curve_point_type(cu->nurb.first);
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
return rna_pointer_inherit_refine(&iter->parent, type, ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rna_ShapeKey_data_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
|
|
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
Key *key = rna_ShapeKey_find_key(ptr->owner_id);
|
2018-12-05 18:30:42 +03:00
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
|
|
|
|
int elemsize = key->elemsize;
|
|
|
|
|
char *databuf = kb->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
memset(r_ptr, 0, sizeof(*r_ptr));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
if (index < 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
if (GS(key->from->name) == ID_CU) {
|
|
|
|
|
NurbInfo info;
|
|
|
|
|
rna_ShapeKey_NurbInfo_find_index(key, index, false, &info);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
if (info.nu && info.nurb_index < info.nurb_size) {
|
|
|
|
|
StructRNA *type = rna_ShapeKey_curve_point_type(info.nu);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
*r_ptr = rna_pointer_inherit_refine(ptr, type, databuf + elemsize * info.elem_index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (index < kb->totelem) {
|
|
|
|
|
*r_ptr = rna_pointer_inherit_refine(ptr, &RNA_ShapeKeyPoint, databuf + elemsize * index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
return false;
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-09-25 01:30:32 +00:00
|
|
|
static char *rna_ShapeKey_path(PointerRNA *ptr)
|
|
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)ptr->data;
|
2019-08-23 09:52:12 +02:00
|
|
|
ID *id = ptr->owner_id;
|
2013-04-23 20:10:22 +00:00
|
|
|
char name_esc[sizeof(kb->name) * 2];
|
|
|
|
|
|
2020-12-10 13:25:49 +11:00
|
|
|
BLI_str_escape(name_esc, kb->name, sizeof(name_esc));
|
2013-04-23 20:10:22 +00:00
|
|
|
|
2019-06-04 00:21:57 +10:00
|
|
|
if ((id) && (GS(id->name) != ID_KE)) {
|
2013-04-23 20:10:22 +00:00
|
|
|
return BLI_sprintfN("shape_keys.key_blocks[\"%s\"]", name_esc);
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-23 20:10:22 +00:00
|
|
|
return BLI_sprintfN("key_blocks[\"%s\"]", name_esc);
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
2009-09-25 01:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 21:30:08 +00:00
|
|
|
static void rna_Key_update_data(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
|
2009-07-03 15:23:33 +00:00
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
Key *key = (Key *)ptr->owner_id;
|
2009-07-03 15:23:33 +00:00
|
|
|
Object *ob;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
|
2012-09-19 10:12:07 +00:00
|
|
|
if (BKE_key_from_object(ob) == key) {
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2012-05-12 11:01:29 +00:00
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
|
2009-07-03 15:23:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
static KeyBlock *rna_ShapeKeyData_find_keyblock(Key *key, float *point)
|
|
|
|
|
{
|
|
|
|
|
KeyBlock *kb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
/* sanity checks */
|
2019-06-04 00:21:57 +10:00
|
|
|
if (ELEM(NULL, key, point)) {
|
2011-01-26 21:58:32 +00:00
|
|
|
return NULL;
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 11:20:52 +10:00
|
|
|
/* We'll need to manually search through the key-blocks and check
|
|
|
|
|
* if the point is somewhere in the middle of each block's data. */
|
2011-01-26 21:58:32 +00:00
|
|
|
for (kb = key->block.first; kb; kb = kb->next) {
|
|
|
|
|
if (kb->data) {
|
|
|
|
|
float *start = (float *)kb->data;
|
|
|
|
|
float *end;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
/* easy cases first */
|
|
|
|
|
if ((start == NULL) || (start > point)) {
|
|
|
|
|
/* there's no chance point is in array */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (start == point) {
|
|
|
|
|
/* exact match - point is first in array */
|
|
|
|
|
return kb;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-18 09:27:36 +00:00
|
|
|
/* determine where end of array is
|
2018-11-14 12:53:15 +11:00
|
|
|
* - elemsize is in bytes, so use (char *) cast to get array in terms of bytes
|
2011-01-26 21:58:32 +00:00
|
|
|
*/
|
|
|
|
|
end = (float *)((char *)start + (key->elemsize * kb->totelem));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 02:48:05 +10:00
|
|
|
/* If point's address is less than the end,
|
|
|
|
|
* then it is somewhere between start and end, so in array. */
|
2011-01-26 21:58:32 +00:00
|
|
|
if (end > point) {
|
|
|
|
|
/* we've found the owner of the point data */
|
|
|
|
|
return kb;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_ShapeKeyPoint_get_index(Key *key, KeyBlock *kb, float *point)
|
|
|
|
|
{
|
2013-10-16 04:08:20 +00:00
|
|
|
/* if we frame the data array and point pointers as (char *), then the difference between
|
2011-01-26 21:58:32 +00:00
|
|
|
* them will be in bytes. Thus, dividing through by key->elemsize (number of bytes per point)
|
|
|
|
|
* gives us the offset of point from start of array.
|
|
|
|
|
*/
|
|
|
|
|
char *start = (char *)kb->data;
|
|
|
|
|
char *pt = (char *)point;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
return (int)(pt - start) / key->elemsize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *rna_ShapeKeyPoint_path(PointerRNA *ptr)
|
|
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
ID *id = ptr->owner_id;
|
|
|
|
|
Key *key = rna_ShapeKey_find_key(ptr->owner_id);
|
2011-01-26 21:58:32 +00:00
|
|
|
KeyBlock *kb;
|
|
|
|
|
float *point = (float *)ptr->data;
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
/* if we can get a key block, we can construct a path */
|
2012-03-18 09:27:36 +00:00
|
|
|
kb = rna_ShapeKeyData_find_keyblock(key, point);
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2011-01-26 21:58:32 +00:00
|
|
|
if (kb) {
|
2013-04-23 20:10:22 +00:00
|
|
|
char name_esc_kb[sizeof(kb->name) * 2];
|
2014-01-02 00:28:02 +13:00
|
|
|
int index;
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
index = rna_ShapeKeyPoint_get_index(key, kb, point);
|
|
|
|
|
|
|
|
|
|
if (ELEM(ptr->type, &RNA_ShapeKeyBezierPoint, &RNA_ShapeKeyCurvePoint)) {
|
|
|
|
|
index = rna_ShapeKey_curve_find_index(key, index);
|
|
|
|
|
}
|
2013-04-23 20:10:22 +00:00
|
|
|
|
2020-12-10 13:25:49 +11:00
|
|
|
BLI_str_escape(name_esc_kb, kb->name, sizeof(name_esc_kb));
|
2018-06-09 14:40:09 +02:00
|
|
|
|
2019-06-04 00:21:57 +10:00
|
|
|
if (GS(id->name) == ID_KE) {
|
2013-04-23 20:10:22 +00:00
|
|
|
return BLI_sprintfN("key_blocks[\"%s\"].data[%d]", name_esc_kb, index);
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-23 20:10:22 +00:00
|
|
|
return BLI_sprintfN("shape_keys.key_blocks[\"%s\"].data[%d]", name_esc_kb, index);
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
2011-01-26 21:58:32 +00:00
|
|
|
}
|
2019-06-04 00:21:57 +10:00
|
|
|
else {
|
2012-05-12 11:01:29 +00:00
|
|
|
return NULL; /* XXX: there's really no way to resolve this... */
|
2019-06-04 00:21:57 +10:00
|
|
|
}
|
2011-01-26 21:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-03 21:18:10 +00:00
|
|
|
#else
|
|
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
const EnumPropertyItem rna_enum_keyblock_type_items[] = {
|
2012-05-22 13:43:36 +00:00
|
|
|
{KEY_LINEAR, "KEY_LINEAR", 0, "Linear", ""},
|
|
|
|
|
{KEY_CARDINAL, "KEY_CARDINAL", 0, "Cardinal", ""},
|
2013-06-25 10:49:20 +00:00
|
|
|
{KEY_CATMULL_ROM, "KEY_CATMULL_ROM", 0, "Catmull-Rom", ""},
|
2012-05-22 13:43:36 +00:00
|
|
|
{KEY_BSPLINE, "KEY_BSPLINE", 0, "BSpline", ""},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2012-05-22 13:43:36 +00:00
|
|
|
};
|
|
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
static const float tilt_limit = DEG2RADF(21600.0f);
|
|
|
|
|
|
2008-12-04 01:58:14 +00:00
|
|
|
static void rna_def_keydata(BlenderRNA *brna)
|
|
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
|
|
|
|
PropertyRNA *prop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "ShapeKeyPoint", NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Shape Key Point", "Point in a shape key");
|
2011-01-26 21:58:32 +00:00
|
|
|
RNA_def_struct_path_func(srna, "rna_ShapeKeyPoint_path");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_array(prop, 3);
|
|
|
|
|
RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Location", "");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "ShapeKeyCurvePoint", NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Shape Key Curve Point", "Point in a shape key for curves");
|
2012-05-12 11:01:29 +00:00
|
|
|
/* there's nothing type specific here, so this is fine for now */
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_struct_path_func(srna, "rna_ShapeKeyPoint_path");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_array(prop, 3);
|
|
|
|
|
RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Location", "");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
prop = RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_ANGLE);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, "rna_ShapeKeyCurvePoint_tilt_get", "rna_ShapeKeyCurvePoint_tilt_set", NULL);
|
2018-12-05 18:30:42 +03:00
|
|
|
RNA_def_property_range(prop, -tilt_limit, tilt_limit);
|
|
|
|
|
RNA_def_property_ui_range(prop, -tilt_limit, tilt_limit, 10, 3);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Tilt", "Tilt in 3D View");
|
|
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_NONE);
|
|
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, "rna_ShapeKeyCurvePoint_radius_get", "rna_ShapeKeyCurvePoint_radius_set", NULL);
|
|
|
|
|
RNA_def_property_range(prop, 0.0f, FLT_MAX);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Radius", "Radius for beveling");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "ShapeKeyBezierPoint", NULL);
|
2011-04-11 01:18:25 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Shape Key Bezier Point", "Point in a shape key for Bezier curves");
|
2012-05-12 11:01:29 +00:00
|
|
|
/* there's nothing type specific here, so this is fine for now */
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_struct_path_func(srna, "rna_ShapeKeyPoint_path");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_array(prop, 3);
|
|
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, "rna_ShapeKeyBezierPoint_co_get", "rna_ShapeKeyBezierPoint_co_set", NULL);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Location", "");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "handle_left", PROP_FLOAT, PROP_TRANSLATION);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_array(prop, 3);
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_property_float_funcs(prop,
|
|
|
|
|
"rna_ShapeKeyBezierPoint_handle_1_co_get",
|
|
|
|
|
"rna_ShapeKeyBezierPoint_handle_1_co_set",
|
|
|
|
|
NULL);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Handle 1 Location", "");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "handle_right", PROP_FLOAT, PROP_TRANSLATION);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_array(prop, 3);
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_property_float_funcs(prop,
|
|
|
|
|
"rna_ShapeKeyBezierPoint_handle_2_co_get",
|
|
|
|
|
"rna_ShapeKeyBezierPoint_handle_2_co_set",
|
|
|
|
|
NULL);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Handle 2 Location", "");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
prop = RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_ANGLE);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, "rna_ShapeKeyBezierPoint_tilt_get", "rna_ShapeKeyBezierPoint_tilt_set", NULL);
|
2018-12-05 18:30:42 +03:00
|
|
|
RNA_def_property_range(prop, -tilt_limit, tilt_limit);
|
|
|
|
|
RNA_def_property_ui_range(prop, -tilt_limit, tilt_limit, 10, 3);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Tilt", "Tilt in 3D View");
|
|
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-05 18:30:42 +03:00
|
|
|
prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_NONE);
|
|
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, "rna_ShapeKeyBezierPoint_radius_get", "rna_ShapeKeyBezierPoint_radius_set", NULL);
|
|
|
|
|
RNA_def_property_range(prop, 0.0f, FLT_MAX);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Radius", "Radius for beveling");
|
2012-03-09 18:28:30 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2008-12-04 01:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_def_keyblock(BlenderRNA *brna)
|
2008-12-03 21:18:10 +00:00
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
2015-10-12 20:12:55 +02:00
|
|
|
PropertyRNA *prop, *parm;
|
|
|
|
|
FunctionRNA *func;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "ShapeKey", NULL);
|
2015-10-24 02:44:43 +11:00
|
|
|
RNA_def_struct_ui_text(srna, "Shape Key", "Shape key in a shape keys data-block");
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_struct_sdna(srna, "KeyBlock");
|
2009-09-25 01:30:32 +00:00
|
|
|
RNA_def_struct_path_func(srna, "rna_ShapeKey_path");
|
2009-06-03 23:16:51 +00:00
|
|
|
RNA_def_struct_ui_icon(srna, ICON_SHAPEKEY_DATA);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
2011-05-15 17:59:48 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Name", "Name of Shape Key");
|
Bugfix #19663: Renaming named data doesn't fix F-Curves
RNA Paths used in F-Curve, Drivers, etc. now get renamed when some data that they use gets renamed. This only works when things like Bones, Constraints, Shape Keys, and Modifiers get renamed, but other cases can get added easily.
The code here only performs simple string replacements, so there is the potential for problems when several sets of data with the same names are present. For example, if there are multiple armatures with bones that have the same names, renaming a bone on one armature (with a bone on another armature having the same name) will break all the drivers on the other one, even though they aren't really connected. However, I don't expect the aforementioned scenario to really be a problem in most production scenarios.
2009-10-20 03:44:35 +00:00
|
|
|
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ShapeKey_name_set");
|
2014-05-18 20:30:48 +02:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_struct_name_property(srna, prop);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-04 01:58:14 +00:00
|
|
|
/* keys need to be sorted to edit this */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_TIME);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_float_sdna(prop, NULL, "pos");
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
RNA_def_property_float_funcs(prop, "rna_ShapeKey_frame_get", NULL, NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Frame", "Frame for absolute keys");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-18 09:27:36 +00:00
|
|
|
/* for now, this is editable directly, as users can set this even if they're not animating them
|
|
|
|
|
* (to test results) */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_FACTOR);
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_float_sdna(prop, NULL, "curval");
|
2020-06-30 12:06:24 +02:00
|
|
|
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
|
2009-08-01 06:03:08 +00:00
|
|
|
RNA_def_property_float_funcs(prop, NULL, "rna_ShapeKey_value_set", "rna_ShapeKey_value_range");
|
2009-10-21 20:58:10 +00:00
|
|
|
RNA_def_property_ui_range(prop, -10.0f, 10.0f, 10, 3);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Value", "Value of shape key at the current frame");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
|
2008-12-03 22:35:38 +00:00
|
|
|
RNA_def_property_enum_sdna(prop, NULL, "type");
|
2015-11-23 13:49:52 +11:00
|
|
|
RNA_def_property_enum_items(prop, rna_enum_keyblock_type_items);
|
2012-05-22 13:43:36 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Interpolation", "Interpolation type for absolute shape keys");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "vgroup");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Vertex Group", "Vertex weight group, to blend with basis shape");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "relative_key", PROP_POINTER, PROP_NONE);
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_struct_type(prop, "ShapeKey");
|
2018-04-16 16:38:28 +02:00
|
|
|
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL | PROP_PTR_NO_OWNERSHIP);
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_property_pointer_funcs(
|
|
|
|
|
prop, "rna_ShapeKey_relative_key_get", "rna_ShapeKey_relative_key_set", NULL, NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Relative Key", "Shape used as a relative key");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYBLOCK_MUTE);
|
2020-06-30 12:06:24 +02:00
|
|
|
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
|
2019-02-20 18:56:26 +01:00
|
|
|
RNA_def_property_ui_text(prop, "Mute", "Toggle this shape key");
|
|
|
|
|
RNA_def_property_ui_icon(prop, ICON_CHECKBOX_HLT, -1);
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "slider_min", PROP_FLOAT, PROP_NONE);
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_float_sdna(prop, NULL, "slidermin");
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_range(prop, -10.0f, 10.0f);
|
2011-01-03 11:58:19 +00:00
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, NULL, "rna_ShapeKey_slider_min_set", "rna_ShapeKey_slider_min_range");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Slider Min", "Minimum for slider");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "slider_max", PROP_FLOAT, PROP_NONE);
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_float_sdna(prop, NULL, "slidermax");
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_range(prop, -10.0f, 10.0f);
|
2009-08-01 06:03:08 +00:00
|
|
|
RNA_def_property_float_default(prop, 1.0f);
|
2011-01-03 11:58:19 +00:00
|
|
|
RNA_def_property_float_funcs(
|
|
|
|
|
prop, NULL, "rna_ShapeKey_slider_max_set", "rna_ShapeKey_slider_max_range");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Slider Max", "Maximum for slider");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_collection_sdna(prop, NULL, "data", "totelem");
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_struct_type(prop, "UnknownType");
|
2020-06-30 12:06:24 +02:00
|
|
|
RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
|
2008-12-04 01:58:14 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Data", "");
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_property_collection_funcs(prop,
|
|
|
|
|
"rna_ShapeKey_data_begin",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
"rna_ShapeKey_data_get",
|
2018-12-05 18:30:42 +03:00
|
|
|
"rna_ShapeKey_data_length",
|
|
|
|
|
"rna_ShapeKey_data_lookup_int",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 02:48:05 +10:00
|
|
|
/* XXX multi-dim dynamic arrays are very badly supported by (py)rna currently,
|
|
|
|
|
* those are defined for the day it works better, for now user will get a 1D tuple.
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2015-10-12 20:12:55 +02:00
|
|
|
func = RNA_def_function(srna, "normals_vertex_get", "rna_KeyBlock_normals_vert_calc");
|
|
|
|
|
RNA_def_function_ui_description(func,
|
|
|
|
|
"Compute local space vertices' normals for this shape key");
|
|
|
|
|
RNA_def_function_flag(func, FUNC_USE_SELF_ID);
|
|
|
|
|
parm = RNA_def_property(func, "normals", PROP_FLOAT, /* PROP_DIRECTION */ PROP_NONE);
|
Refactor RNA property: split flags in property flags, parameter flags, and internal flags.
This gives us 9 flags available again for properties (we had none anymore),
and also makes things slightly cleaner.
To simplify (and make more clear the differences between mere properties
and function parameters), also added RNA_def_parameter_flags function (and
its clear counterpart), to be used instead of RNA_def_property_flag for
function parameters.
This patch is also a big cleanup (some RNA function definitions were
still using 'prop' PropertyRNA pointer, etc.).
And yes, am aware this will be annoying for all branches, but we really need
to get new flags available for properties (will need at least one for override, etc.).
Reviewers: sergey, Severin
Subscribers: dfelinto, brecht
Differential Revision: https://developer.blender.org/D2400
2016-12-12 15:23:55 +01:00
|
|
|
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
|
2015-10-12 20:12:55 +02:00
|
|
|
RNA_def_property_multi_array(parm, 2, NULL);
|
|
|
|
|
RNA_def_property_range(parm, -1.0f, 1.0f);
|
|
|
|
|
RNA_def_property_dynamic_array_funcs(parm, "rna_KeyBlock_normals_vert_len");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-12 20:12:55 +02:00
|
|
|
func = RNA_def_function(srna, "normals_polygon_get", "rna_KeyBlock_normals_poly_calc");
|
|
|
|
|
RNA_def_function_ui_description(func, "Compute local space faces' normals for this shape key");
|
|
|
|
|
RNA_def_function_flag(func, FUNC_USE_SELF_ID);
|
|
|
|
|
parm = RNA_def_property(func, "normals", PROP_FLOAT, /* PROP_DIRECTION */ PROP_NONE);
|
Refactor RNA property: split flags in property flags, parameter flags, and internal flags.
This gives us 9 flags available again for properties (we had none anymore),
and also makes things slightly cleaner.
To simplify (and make more clear the differences between mere properties
and function parameters), also added RNA_def_parameter_flags function (and
its clear counterpart), to be used instead of RNA_def_property_flag for
function parameters.
This patch is also a big cleanup (some RNA function definitions were
still using 'prop' PropertyRNA pointer, etc.).
And yes, am aware this will be annoying for all branches, but we really need
to get new flags available for properties (will need at least one for override, etc.).
Reviewers: sergey, Severin
Subscribers: dfelinto, brecht
Differential Revision: https://developer.blender.org/D2400
2016-12-12 15:23:55 +01:00
|
|
|
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
|
2015-10-12 20:12:55 +02:00
|
|
|
RNA_def_property_multi_array(parm, 2, NULL);
|
|
|
|
|
RNA_def_property_range(parm, -1.0f, 1.0f);
|
|
|
|
|
RNA_def_property_dynamic_array_funcs(parm, "rna_KeyBlock_normals_poly_len");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-12 20:12:55 +02:00
|
|
|
func = RNA_def_function(srna, "normals_split_get", "rna_KeyBlock_normals_loop_calc");
|
|
|
|
|
RNA_def_function_ui_description(func,
|
|
|
|
|
"Compute local space face corners' normals for this shape key");
|
|
|
|
|
RNA_def_function_flag(func, FUNC_USE_SELF_ID);
|
|
|
|
|
parm = RNA_def_property(func, "normals", PROP_FLOAT, /* PROP_DIRECTION */ PROP_NONE);
|
Refactor RNA property: split flags in property flags, parameter flags, and internal flags.
This gives us 9 flags available again for properties (we had none anymore),
and also makes things slightly cleaner.
To simplify (and make more clear the differences between mere properties
and function parameters), also added RNA_def_parameter_flags function (and
its clear counterpart), to be used instead of RNA_def_property_flag for
function parameters.
This patch is also a big cleanup (some RNA function definitions were
still using 'prop' PropertyRNA pointer, etc.).
And yes, am aware this will be annoying for all branches, but we really need
to get new flags available for properties (will need at least one for override, etc.).
Reviewers: sergey, Severin
Subscribers: dfelinto, brecht
Differential Revision: https://developer.blender.org/D2400
2016-12-12 15:23:55 +01:00
|
|
|
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
|
2015-10-12 20:12:55 +02:00
|
|
|
RNA_def_property_multi_array(parm, 2, NULL);
|
|
|
|
|
RNA_def_property_range(parm, -1.0f, 1.0f);
|
|
|
|
|
RNA_def_property_dynamic_array_funcs(parm, "rna_KeyBlock_normals_loop_len");
|
2008-12-03 21:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-04 01:58:14 +00:00
|
|
|
static void rna_def_key(BlenderRNA *brna)
|
2008-12-03 21:18:10 +00:00
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
|
|
|
|
PropertyRNA *prop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "Key", "ID");
|
2015-10-24 02:44:43 +11:00
|
|
|
RNA_def_struct_ui_text(
|
|
|
|
|
srna, "Key", "Shape keys data-block containing different shapes of geometric data-blocks");
|
2009-06-03 23:16:51 +00:00
|
|
|
RNA_def_struct_ui_icon(srna, ICON_SHAPEKEY_DATA);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "reference_key", PROP_POINTER, PROP_NONE);
|
2009-09-16 18:04:01 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_NEVER_NULL);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_pointer_sdna(prop, NULL, "refkey");
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Reference Key", "");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "key_blocks", PROP_COLLECTION, PROP_NONE);
|
2008-12-03 21:18:10 +00:00
|
|
|
RNA_def_property_collection_sdna(prop, NULL, "block", NULL);
|
2020-06-30 12:06:24 +02:00
|
|
|
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_struct_type(prop, "ShapeKey");
|
2011-03-25 02:12:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Key Blocks", "Shape keys");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-02-02 11:51:10 +00:00
|
|
|
rna_def_animdata_common(srna);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "user", PROP_POINTER, PROP_NONE);
|
2009-09-16 18:04:01 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_NEVER_NULL);
|
2019-08-20 17:48:10 +02:00
|
|
|
RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
|
2008-12-18 23:34:19 +00:00
|
|
|
RNA_def_property_pointer_sdna(prop, NULL, "from");
|
2016-09-19 16:46:20 +02:00
|
|
|
RNA_def_property_ui_text(prop, "User", "Data-block using these shape keys");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "use_relative", PROP_BOOLEAN, PROP_NONE);
|
2008-12-04 00:07:47 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "type", KEY_RELATIVE);
|
2012-04-05 05:05:18 +00:00
|
|
|
RNA_def_property_ui_text(
|
|
|
|
|
prop,
|
|
|
|
|
"Relative",
|
|
|
|
|
"Make shape keys relative, "
|
|
|
|
|
"otherwise play through shapes as a sequence using the evaluation time");
|
|
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-05 05:05:18 +00:00
|
|
|
prop = RNA_def_property(srna, "eval_time", PROP_FLOAT, PROP_NONE);
|
|
|
|
|
RNA_def_property_float_sdna(prop, NULL, "ctime");
|
|
|
|
|
RNA_def_property_range(prop, MINFRAME, MAXFRAME);
|
2020-06-30 12:06:24 +02:00
|
|
|
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
|
2012-04-05 05:05:18 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Evaluation Time", "Evaluation time for absolute shape keys");
|
2009-07-03 15:23:33 +00:00
|
|
|
RNA_def_property_update(prop, 0, "rna_Key_update_data");
|
2008-12-03 21:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-04 01:58:14 +00:00
|
|
|
void RNA_def_key(BlenderRNA *brna)
|
|
|
|
|
{
|
|
|
|
|
rna_def_key(brna);
|
|
|
|
|
rna_def_keyblock(brna);
|
|
|
|
|
rna_def_keydata(brna);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-03 21:18:10 +00:00
|
|
|
#endif
|