2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-22 10:15:02 +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-22 10:15:02 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edanimation
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* This file contains code for presenting F-Curves and other animation data
|
|
|
|
* in the UI (especially for use in the Animation Editors).
|
2008-12-22 10:15:02 +00:00
|
|
|
*
|
|
|
|
* -- Joshua Leung, Dec 2008
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2008-12-22 10:15:02 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-10 14:57:19 +00:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "RNA_access.h"
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
#include "ED_anim_api.h"
|
|
|
|
|
2008-12-22 10:15:02 +00:00
|
|
|
/* ----------------------- Getter functions ----------------------- */
|
|
|
|
|
2009-11-08 06:43:08 +00:00
|
|
|
/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings),
|
2018-06-01 18:19:39 +02:00
|
|
|
* and return the icon used for the struct that this property refers to
|
2009-08-24 04:31:13 +00:00
|
|
|
* WARNING: name buffer we're writing to cannot exceed 256 chars (check anim_channels_defines.c for details)
|
2008-12-22 10:15:02 +00:00
|
|
|
*/
|
2009-11-08 06:43:08 +00:00
|
|
|
int getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
|
2009-01-25 04:02:31 +00:00
|
|
|
{
|
2009-11-08 06:43:08 +00:00
|
|
|
int icon = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* sanity checks */
|
|
|
|
if (name == NULL)
|
2009-11-08 06:43:08 +00:00
|
|
|
return icon;
|
2014-07-20 01:30:29 +10:00
|
|
|
else if (ELEM(NULL, id, fcu, fcu->rna_path)) {
|
2009-01-25 04:02:31 +00:00
|
|
|
if (fcu == NULL)
|
2013-03-10 14:57:19 +00:00
|
|
|
strcpy(name, IFACE_("<invalid>"));
|
2009-01-25 04:02:31 +00:00
|
|
|
else if (fcu->rna_path == NULL)
|
2013-03-10 14:57:19 +00:00
|
|
|
strcpy(name, IFACE_("<no path>"));
|
2009-01-25 04:02:31 +00:00
|
|
|
else /* id == NULL */
|
2009-11-08 06:43:08 +00:00
|
|
|
BLI_snprintf(name, 256, "%s[%d]", fcu->rna_path, fcu->array_index);
|
2009-01-25 04:02:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PointerRNA id_ptr, ptr;
|
|
|
|
PropertyRNA *prop;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* get RNA pointer, and resolve the path */
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* try to resolve the path */
|
Bugfix [#34836] Crash when driver variable has path == 'data'
Most of the places which relied on RNA_path_resolve() did so believing that if
it returned true, that it had found a valid property, and that the returned
pointer+property combination would be what the path referred to. However, it
turns out that if the property at the end of the path turns out to be a
"pointer" property (e.g. "data" for Object.data), this would automatically
become the pointer part, while the prop part would be set to null. Hence, if a
user accidentally (or otherwise) specifies a path for the single-property driver
variable type like this, then Blender would crash.
This commit introduces two convenience functions - RNA_path_resolve_property()
and RNA_path_resolve_property_full() - which mirror/wrap the existing
RNA_path_resolve() functions. The only difference though is that these include a
check to ensure that what was found from resolving the path was in fact a
property (they only return true iff this is the case), and make it explicitly
clear in the name that this is what they will do so that there's no further
confusion. It is possible to do without these wrapper functions by doing these
checks inline, but the few cases that had been patched already were pretty
hideous looking specimens. Using these just make it clearer and simpler for all.
I've also beefed up the docs on these a bit, and changed these to using bools.
2013-04-22 13:22:07 +00:00
|
|
|
if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
|
2012-05-08 15:30:00 +00:00
|
|
|
const char *structname = NULL, *propname = NULL;
|
2011-12-09 01:27:59 +00:00
|
|
|
char arrayindbuf[16];
|
2012-05-08 15:30:00 +00:00
|
|
|
const char *arrayname = NULL;
|
2009-10-09 12:15:46 +00:00
|
|
|
short free_structname = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-16 09:48:38 +00:00
|
|
|
/* For now, name will consist of 3 parts: struct-name, property name, array index
|
|
|
|
* There are several options possible:
|
2018-11-14 12:53:15 +11:00
|
|
|
* 1) <struct-name>.<property-name>.<array-index>
|
|
|
|
* i.e. Bone1.Location.X, or Object.Location.X
|
|
|
|
* 2) <array-index> <property-name> (<struct name>)
|
|
|
|
* i.e. X Location (Bone1), or X Location (Object)
|
2012-10-21 05:46:41 +00:00
|
|
|
*
|
2009-02-16 09:48:38 +00:00
|
|
|
* Currently, option 2 is in use, to try and make it easier to quickly identify F-Curves (it does have
|
2018-06-04 09:31:30 +02:00
|
|
|
* problems with looking rather odd though). Option 1 is better in terms of revealing a consistent sense of
|
2009-02-16 09:48:38 +00:00
|
|
|
* hierarchy though, which isn't so clear with option 2.
|
2008-12-22 10:15:02 +00:00
|
|
|
*/
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-10-09 12:15:46 +00:00
|
|
|
/* for structname
|
2018-11-14 12:53:15 +11:00
|
|
|
* - as base, we use a custom name from the structs if one is available
|
|
|
|
* - however, if we're showing subdata of bones (probably there will be other exceptions later)
|
|
|
|
* need to include that info too since it gets confusing otherwise
|
|
|
|
* - if a pointer just refers to the ID-block, then don't repeat this info
|
|
|
|
* since this just introduces clutter
|
2009-10-09 12:15:46 +00:00
|
|
|
*/
|
2009-11-18 11:40:55 +00:00
|
|
|
if (strstr(fcu->rna_path, "bones") && strstr(fcu->rna_path, "constraints")) {
|
2009-10-09 12:15:46 +00:00
|
|
|
/* perform string 'chopping' to get "Bone Name : Constraint Name" */
|
2012-07-09 22:16:50 +00:00
|
|
|
char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
|
|
|
|
char *constName = BLI_str_quoted_substrN(fcu->rna_path, "constraints[");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-10-09 12:15:46 +00:00
|
|
|
/* assemble the string to display in the UI... */
|
2012-05-08 15:30:00 +00:00
|
|
|
structname = BLI_sprintfN("%s : %s", pchanName, constName);
|
|
|
|
free_structname = 1;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-10-09 12:15:46 +00:00
|
|
|
/* free the temp names */
|
|
|
|
if (pchanName) MEM_freeN(pchanName);
|
|
|
|
if (constName) MEM_freeN(constName);
|
|
|
|
}
|
2011-06-30 01:07:03 +00:00
|
|
|
else if (ptr.data != ptr.id.data) {
|
2012-05-08 15:30:00 +00:00
|
|
|
PropertyRNA *nameprop = RNA_struct_name_property(ptr.type);
|
2009-10-09 12:15:46 +00:00
|
|
|
if (nameprop) {
|
|
|
|
/* this gets a string which will need to be freed */
|
2012-05-08 15:30:00 +00:00
|
|
|
structname = RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0, NULL);
|
|
|
|
free_structname = 1;
|
2009-10-09 12:15:46 +00:00
|
|
|
}
|
|
|
|
else
|
2012-05-08 15:30:00 +00:00
|
|
|
structname = RNA_struct_ui_name(ptr.type);
|
2009-01-25 04:02:31 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* Property Name is straightforward */
|
2012-05-08 15:30:00 +00:00
|
|
|
propname = RNA_property_ui_name(prop);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-30 08:10:31 +00:00
|
|
|
/* Array Index - only if applicable */
|
2013-09-16 01:35:52 +00:00
|
|
|
if (RNA_property_array_check(prop)) {
|
2012-05-08 15:30:00 +00:00
|
|
|
char c = RNA_property_array_item_char(prop, fcu->array_index);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
RNA: subtypes and units
* Reviewed subtypes, making them more specific and adding new ones.
* Subtypes now have an associated type of units (length, area, volume,
mass, rotation, time, velocity, acceleration). These are not used
yet anywhere.
* Centralized code that decides the name of array items based on
subtype (XYZ, RGB), was copied in 3 places.
* RNA_def_float etc functions still need to be update, will do this
later together with another change.
2009-08-10 21:31:05 +00:00
|
|
|
/* we need to write the index to a temp buffer (in py syntax) */
|
2012-01-11 12:33:51 +00:00
|
|
|
if (c) BLI_snprintf(arrayindbuf, sizeof(arrayindbuf), "%c ", c);
|
|
|
|
else BLI_snprintf(arrayindbuf, sizeof(arrayindbuf), "[%d]", fcu->array_index);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
arrayname = &arrayindbuf[0];
|
2009-01-25 04:02:31 +00:00
|
|
|
}
|
2009-01-30 08:10:31 +00:00
|
|
|
else {
|
|
|
|
/* no array index */
|
2012-05-08 15:30:00 +00:00
|
|
|
arrayname = "";
|
2009-01-30 08:10:31 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* putting this all together into the buffer */
|
2012-07-06 23:56:59 +00:00
|
|
|
/* XXX we need to check for invalid names...
|
|
|
|
* XXX the name length limit needs to be passed in or as some define */
|
2011-06-30 01:07:03 +00:00
|
|
|
if (structname)
|
2012-07-06 23:56:59 +00:00
|
|
|
BLI_snprintf(name, 256, "%s%s (%s)", arrayname, propname, structname);
|
2011-06-30 01:07:03 +00:00
|
|
|
else
|
2012-07-06 23:56:59 +00:00
|
|
|
BLI_snprintf(name, 256, "%s%s", arrayname, propname);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* free temp name if nameprop is set */
|
2009-10-09 12:15:46 +00:00
|
|
|
if (free_structname)
|
2011-12-09 01:27:59 +00:00
|
|
|
MEM_freeN((void *)structname);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
|
|
|
2009-11-08 06:43:08 +00:00
|
|
|
/* Icon for this property's owner:
|
2018-11-14 12:53:15 +11:00
|
|
|
* use the struct's icon if it is set
|
2009-11-08 06:43:08 +00:00
|
|
|
*/
|
2012-05-08 15:30:00 +00:00
|
|
|
icon = RNA_struct_ui_icon(ptr.type);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-01-03 02:11:11 +00:00
|
|
|
/* valid path - remove the invalid tag since we now know how to use it saving
|
|
|
|
* users manual effort to reenable using "Revive Disabled FCurves" [#29629]
|
|
|
|
*/
|
|
|
|
fcu->flag &= ~FCURVE_DISABLED;
|
2009-01-25 04:02:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* invalid path */
|
2009-11-08 06:43:08 +00:00
|
|
|
BLI_snprintf(name, 256, "\"%s[%d]\"", fcu->rna_path, fcu->array_index);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-08 06:43:08 +00:00
|
|
|
/* icon for this should be the icon for the base ID */
|
2012-07-06 23:56:59 +00:00
|
|
|
/* TODO: or should we just use the error icon? */
|
2012-05-08 15:30:00 +00:00
|
|
|
icon = RNA_struct_ui_icon(id_ptr.type);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-09-07 12:03:09 +00:00
|
|
|
/* tag F-Curve as disabled - as not usable path */
|
|
|
|
fcu->flag |= FCURVE_DISABLED;
|
2009-01-25 04:02:31 +00:00
|
|
|
}
|
2008-12-22 10:15:02 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-08 06:43:08 +00:00
|
|
|
/* return the icon that the active data had */
|
|
|
|
return icon;
|
2008-12-22 10:15:02 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* ------------------------------- Color Codes for F-Curve Channels ---------------------------- */
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2009-05-11 11:41:08 +00:00
|
|
|
/* step between the major distinguishable color bands of the primary colors */
|
2012-05-08 15:30:00 +00:00
|
|
|
#define HSV_BANDWIDTH 0.3f
|
2009-05-11 11:41:08 +00:00
|
|
|
|
2010-12-03 12:30:59 +00:00
|
|
|
/* used to determine the color of F-Curves with FCURVE_COLOR_AUTO_RAINBOW set */
|
2016-06-22 14:02:51 +10:00
|
|
|
// void fcurve_rainbow(unsigned int cur, unsigned int tot, float *out)
|
2012-05-26 11:01:01 +00:00
|
|
|
void getcolor_fcurve_rainbow(int cur, int tot, float out[3])
|
2009-05-11 11:41:08 +00:00
|
|
|
{
|
2012-05-26 11:01:01 +00:00
|
|
|
float hsv[3], fac;
|
2009-05-11 11:41:08 +00:00
|
|
|
int grouping;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-12-03 12:30:59 +00:00
|
|
|
/* we try to divide the color into groupings of n colors,
|
2009-05-11 11:41:08 +00:00
|
|
|
* where n is:
|
2018-11-14 12:53:15 +11:00
|
|
|
* 3 - for 'odd' numbers of curves - there should be a majority of triplets of curves
|
|
|
|
* 4 - for 'even' numbers of curves - there should be a majority of quartets of curves
|
2009-05-11 11:41:08 +00:00
|
|
|
* so the base color is simply one of the three primary colors
|
|
|
|
*/
|
2012-05-08 15:30:00 +00:00
|
|
|
grouping = (4 - (tot % 2));
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv[0] = HSV_BANDWIDTH * (float)(cur % grouping);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
|
|
/* 'Value' (i.e. darkness) needs to vary so that larger sets of three will be
|
2009-05-11 11:41:08 +00:00
|
|
|
* 'darker' (i.e. smaller value), so that they don't look that similar to previous ones.
|
|
|
|
* However, only a range of 0.3 to 1.0 is really usable to avoid clashing
|
2018-06-04 09:31:30 +02:00
|
|
|
* with some other stuff
|
2009-05-11 11:41:08 +00:00
|
|
|
*/
|
|
|
|
fac = ((float)cur / (float)tot) * 0.7f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-05-11 11:41:08 +00:00
|
|
|
/* the base color can get offset a bit so that the colors aren't so identical */
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv[0] += fac * HSV_BANDWIDTH;
|
|
|
|
if (hsv[0] > 1.0f) hsv[0] = fmod(hsv[0], 1.0f);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-05-18 02:23:20 +00:00
|
|
|
/* saturation adjustments for more visible range */
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv[1] = ((hsv[0] > 0.5f) && (hsv[0] < 0.8f)) ? 0.5f : 0.6f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-05-18 02:23:20 +00:00
|
|
|
/* value is fixed at 1.0f, otherwise we cannot clearly see the curves... */
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv[2] = 1.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-05-11 11:41:08 +00:00
|
|
|
/* finally, conver this to RGB colors */
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv_to_rgb_v(hsv, out);
|
2009-05-11 11:41:08 +00:00
|
|
|
}
|