2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-22 10:15:02 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation, 2005. Full recode
|
|
|
|
* Joshua Leung
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/animation/anim_ipo_utils.c
|
|
|
|
* \ingroup edanimation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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),
|
|
|
|
* 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;
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* sanity checks */
|
|
|
|
if (name == NULL)
|
2009-11-08 06:43:08 +00:00
|
|
|
return icon;
|
2012-03-25 22:35:18 +00:00
|
|
|
else if (ELEM3(NULL, id, fcu, fcu->rna_path)) {
|
2009-01-25 04:02:31 +00:00
|
|
|
if (fcu == NULL)
|
2011-10-09 06:03:38 +00:00
|
|
|
strcpy(name, "<invalid>");
|
2009-01-25 04:02:31 +00:00
|
|
|
else if (fcu->rna_path == NULL)
|
2011-10-09 06:03:38 +00:00
|
|
|
strcpy(name, "<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;
|
|
|
|
|
|
|
|
/* get RNA pointer, and resolve the path */
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
|
|
|
|
|
|
|
/* try to resolve the path */
|
|
|
|
if (RNA_path_resolve(&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;
|
2008-12-22 10:15:02 +00: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:
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
* Currently, option 2 is in use, to try and make it easier to quickly identify F-Curves (it does have
|
|
|
|
* problems with looking rather odd though). Option 1 is better in terms of revealing a consistent sense of
|
|
|
|
* hierarchy though, which isn't so clear with option 2.
|
2008-12-22 10:15:02 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-09 12:15:46 +00:00
|
|
|
/* for structname
|
|
|
|
* - 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
|
2011-06-30 01:07:03 +00:00
|
|
|
* - 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[");
|
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;
|
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
|
|
|
}
|
2008-12-22 10:15:02 +00: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);
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2009-01-30 08:10:31 +00:00
|
|
|
/* Array Index - only if applicable */
|
Implemented dynamic and multidimensional array support in RNA.
Example code: http://www.pasteall.org/7332/c.
New API functions: http://www.pasteall.org/7330/c.
Maximum number of dimensions is currently limited to 3, but can be increased arbitrarily if needed.
What this means for ID property access:
* MeshFace.verts - dynamic array, size 3 or 4 depending on MFace.v4
* MeshTextureFace.uv - dynamic, 2-dimensional array, size depends on MFace.v4
* Object.matrix - 2-dimensional array
What this means for functions:
* more intuitive API possibility, for example:
Mesh.add_vertices([(x, y, z), (x, y, z), ...])
Mesh.add_faces([(1, 2, 3), (4, 5, 6), ...])
Python part is not complete yet, e.g. it is possible to:
MeshFace.verts = (1, 2, 3) # even if Mesh.verts is (1, 2, 3, 4) and vice-versa
MeshTextureFace.uv = [(0.0, 0.0)] * 4 # only if a corresponding MFace is a quad
but the following won't work:
MeshTextureFace.uv[3] = (0.0, 0.0) # setting uv[3] modifies MTFace.uv[1][0] instead of MTFace.uv[3]
2009-08-25 17:06:36 +00:00
|
|
|
if (RNA_property_array_length(&ptr, prop)) {
|
2012-05-08 15:30:00 +00:00
|
|
|
char c = RNA_property_array_item_char(prop, fcu->array_index);
|
2009-01-25 04:02:31 +00: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);
|
2009-10-09 12:15:46 +00: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
|
|
|
}
|
2012-07-06 23:56:59 +00: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);
|
|
|
|
|
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);
|
2009-11-08 06:43:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Icon for this property's owner:
|
|
|
|
* use the struct's icon if it is set
|
|
|
|
*/
|
2012-05-08 15:30:00 +00:00
|
|
|
icon = RNA_struct_ui_icon(ptr.type);
|
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);
|
2012-07-06 23:56:59 +00: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);
|
2012-07-06 23:56:59 +00: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
|
|
|
}
|
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 */
|
2009-05-11 11:41:08 +00: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;
|
|
|
|
|
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:
|
|
|
|
* 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
|
|
|
|
* 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);
|
2009-05-11 11:41:08 +00:00
|
|
|
|
|
|
|
/* 'Value' (i.e. darkness) needs to vary so that larger sets of three will be
|
|
|
|
* '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
|
|
|
|
* with some other stuff
|
|
|
|
*/
|
|
|
|
fac = ((float)cur / (float)tot) * 0.7f;
|
|
|
|
|
|
|
|
/* 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);
|
2009-05-11 11:41:08 +00: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;
|
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;
|
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
|
|
|
}
|