2008-12-22 10:15:02 +00:00
|
|
|
/**
|
|
|
|
|
* $Id:
|
|
|
|
|
*
|
|
|
|
|
* ***** 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,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* 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 *****
|
|
|
|
|
*/
|
|
|
|
|
|
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-06-08 20:08:19 +00:00
|
|
|
#include <math.h>
|
2008-12-22 10:15:02 +00:00
|
|
|
#include <stdio.h>
|
2009-10-09 12:15:46 +00:00
|
|
|
#include <string.h>
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2008-12-22 10:15:02 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2008-12-22 10:15:02 +00:00
|
|
|
#include "DNA_key_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "BKE_animsys.h"
|
2008-12-22 10:15:02 +00:00
|
|
|
#include "BKE_key.h"
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
#include "ED_anim_api.h"
|
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_types.h"
|
2008-12-22 10:15:02 +00:00
|
|
|
|
|
|
|
|
/* ----------------------- Getter functions ----------------------- */
|
|
|
|
|
|
|
|
|
|
/* gets the appropriate icon for the given blocktype */
|
2009-01-25 04:02:31 +00:00
|
|
|
// XXX some of these will be depreceated?
|
|
|
|
|
int geticon_anim_blocktype(short blocktype)
|
2008-12-22 10:15:02 +00:00
|
|
|
{
|
|
|
|
|
switch (blocktype) {
|
|
|
|
|
case ID_OB:
|
2009-02-18 05:54:37 +00:00
|
|
|
return ICON_OBJECT_DATA;
|
2008-12-22 10:15:02 +00:00
|
|
|
case ID_PO:
|
|
|
|
|
return ICON_POSE_HLT;
|
|
|
|
|
case ID_KE:
|
2009-02-18 05:54:37 +00:00
|
|
|
return ICON_SHAPEKEY_DATA;
|
2008-12-22 10:15:02 +00:00
|
|
|
case ID_MA:
|
|
|
|
|
return ICON_MATERIAL;
|
|
|
|
|
case ID_WO:
|
|
|
|
|
return ICON_WORLD;
|
|
|
|
|
case ID_CU:
|
2009-02-18 05:54:37 +00:00
|
|
|
return ICON_CURVE_DATA;
|
2008-12-22 10:15:02 +00:00
|
|
|
case ID_CA:
|
|
|
|
|
return ICON_CAMERA;
|
|
|
|
|
case ID_LA:
|
|
|
|
|
return ICON_LAMP;
|
|
|
|
|
case ID_TE:
|
|
|
|
|
return ICON_TEXTURE;
|
|
|
|
|
case ID_CO:
|
|
|
|
|
return ICON_CONSTRAINT;
|
|
|
|
|
case ID_FLUIDSIM:
|
|
|
|
|
return ICON_WORLD; // uggh
|
|
|
|
|
default:
|
|
|
|
|
return 0; // what about blank icon?
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-09 12:15:46 +00:00
|
|
|
/* helper function for getname_*() - grabs the text within the "" that starts with 'blahblah'
|
|
|
|
|
* i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples"
|
|
|
|
|
*
|
|
|
|
|
* - str: is the entire string to chop
|
|
|
|
|
* - prefix: is the part of the string to leave out
|
|
|
|
|
*
|
|
|
|
|
* Assume that the strings returned must be freed afterwards, and that the inputs will contain
|
|
|
|
|
* data we want...
|
|
|
|
|
*/
|
|
|
|
|
static char *grab_quoted_text (const char *str, const char *prefix)
|
|
|
|
|
{
|
|
|
|
|
int prefixLen = strlen(prefix);
|
|
|
|
|
char *startMatch, *endMatch;
|
|
|
|
|
|
|
|
|
|
/* get the starting point (i.e. where prefix starts, and add prefixLen+1 to it to get be after the first " */
|
|
|
|
|
startMatch= strstr(str, prefix) + prefixLen + 1;
|
|
|
|
|
|
|
|
|
|
/* get the end point (i.e. where the next occurance of " is after the starting point) */
|
|
|
|
|
endMatch= strchr(startMatch, '"'); // " NOTE: this comment here is just so that my text editor still shows the functions ok...
|
|
|
|
|
|
|
|
|
|
/* return the slice indicated */
|
|
|
|
|
return BLI_strdupn(startMatch, (int)(endMatch-startMatch));
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-25 04:02:31 +00:00
|
|
|
/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings)
|
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-01-25 04:02:31 +00:00
|
|
|
void getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
|
|
|
|
|
{
|
|
|
|
|
/* sanity checks */
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
return;
|
|
|
|
|
else if ELEM3(NULL, id, fcu, fcu->rna_path) {
|
|
|
|
|
if (fcu == NULL)
|
|
|
|
|
sprintf(name, "<invalid>");
|
|
|
|
|
else if (fcu->rna_path == NULL)
|
|
|
|
|
sprintf(name, "<no path>");
|
|
|
|
|
else /* id == NULL */
|
|
|
|
|
BLI_snprintf(name, 128, "%s[%d]", fcu->rna_path, fcu->array_index);
|
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
|
char *structname=NULL, *propname=NULL, *arrayname=NULL, arrayindbuf[16];
|
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
|
|
|
|
|
*/
|
|
|
|
|
if (strstr(fcu->rna_path, "pose_channels") && strstr(fcu->rna_path, "constraints")) {
|
|
|
|
|
/* perform string 'chopping' to get "Bone Name : Constraint Name" */
|
|
|
|
|
char *pchanName= grab_quoted_text(fcu->rna_path, "pose_channels[");
|
|
|
|
|
char *constName= grab_quoted_text(fcu->rna_path, "constraints[");
|
|
|
|
|
|
|
|
|
|
/* assemble the string to display in the UI... */
|
|
|
|
|
structname= BLI_sprintfN("%s : %s", pchanName, constName);
|
|
|
|
|
free_structname= 1;
|
|
|
|
|
|
|
|
|
|
/* free the temp names */
|
|
|
|
|
if (pchanName) MEM_freeN(pchanName);
|
|
|
|
|
if (constName) MEM_freeN(constName);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
PropertyRNA *nameprop= RNA_struct_name_property(ptr.type);
|
|
|
|
|
if (nameprop) {
|
|
|
|
|
/* this gets a string which will need to be freed */
|
|
|
|
|
structname= RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0);
|
|
|
|
|
free_structname= 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
structname= (char *)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 */
|
2009-04-19 13:37:59 +00:00
|
|
|
propname= (char *)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)) {
|
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
|
|
|
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) */
|
2009-10-09 12:15:46 +00:00
|
|
|
if (c) sprintf(arrayindbuf, "%c ", c);
|
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
|
|
|
else sprintf(arrayindbuf, "[%d]", fcu->array_index);
|
2009-10-09 12:15:46 +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
|
|
|
arrayname= &arrayindbuf[0];
|
2009-01-25 04:02:31 +00:00
|
|
|
}
|
2009-01-30 08:10:31 +00:00
|
|
|
else {
|
|
|
|
|
/* no array index */
|
|
|
|
|
arrayname= "";
|
|
|
|
|
}
|
2009-01-25 04:02:31 +00:00
|
|
|
|
|
|
|
|
/* putting this all together into the buffer */
|
2009-02-16 09:48:38 +00:00
|
|
|
// XXX we need to check for invalid names...
|
2009-05-11 11:41:08 +00:00
|
|
|
BLI_snprintf(name, 128, "%s%s (%s)", arrayname, propname, structname);
|
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)
|
2009-01-25 04:02:31 +00:00
|
|
|
MEM_freeN(structname);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* invalid path */
|
|
|
|
|
BLI_snprintf(name, 128, "\"%s[%d]\"", fcu->rna_path, fcu->array_index);
|
|
|
|
|
}
|
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
|
|
|
#if 0
|
2009-02-15 10:58:24 +00:00
|
|
|
/* used for FCURVE_COLOR_AUTO_RAINBOW */
|
|
|
|
|
// XXX this still doesn't work too great when there are more than 32 curves (which happens most of the time)
|
|
|
|
|
void ipo_rainbow (int cur, int tot, float *out)
|
2008-12-22 10:15:02 +00:00
|
|
|
{
|
|
|
|
|
float dfac, fac, sat;
|
|
|
|
|
|
|
|
|
|
dfac= (float)(1.0/( (float)tot+1.0));
|
|
|
|
|
|
|
|
|
|
/* this calculation makes 2 or 4 different cycles of rainbow colors */
|
2009-05-11 11:41:08 +00:00
|
|
|
// 2 different cycles - for hue
|
2008-12-22 10:15:02 +00:00
|
|
|
if(cur< tot/2) fac= (float)(cur*2.0f*dfac);
|
|
|
|
|
else fac= (float)((cur-tot/2)*2.0f*dfac +dfac);
|
2009-05-11 11:41:08 +00:00
|
|
|
|
|
|
|
|
// third cycle with altered hue
|
2008-12-22 10:15:02 +00:00
|
|
|
if(tot > 32) fac= fac*1.95f;
|
2009-05-11 11:41:08 +00:00
|
|
|
// clamping for excessive ranges
|
2008-12-22 10:15:02 +00:00
|
|
|
if(fac>1.0f) fac-= 1.0f;
|
|
|
|
|
|
2009-05-11 11:41:08 +00:00
|
|
|
// saturation adjustments for more visible range
|
2009-01-29 03:43:04 +00:00
|
|
|
if(fac>0.5f && fac<0.8f) sat= 0.5f;
|
|
|
|
|
else sat= 0.6f;
|
2008-12-22 10:15:02 +00:00
|
|
|
|
2009-02-15 10:58:24 +00:00
|
|
|
hsv_to_rgb(fac, sat, 1.0f, out, out+1, out+2);
|
2008-12-22 10:15:02 +00:00
|
|
|
}
|
2009-05-11 11:41:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* step between the major distinguishable color bands of the primary colors */
|
|
|
|
|
#define HSV_BANDWIDTH 0.3f
|
|
|
|
|
|
|
|
|
|
/* testbed for FCURVE_COLOR_AUTO_RAINBOW determination methods */
|
|
|
|
|
//void fcurve_rainbow (unsigned int cur, unsigned int tot, float *out)
|
|
|
|
|
void ipo_rainbow (int cur, int tot, float *out)
|
|
|
|
|
{
|
|
|
|
|
float hue, val, sat, fac;
|
|
|
|
|
int grouping;
|
|
|
|
|
|
|
|
|
|
/* we try to divide the colours into groupings of n colors,
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
grouping= (4 - (tot % 2));
|
|
|
|
|
hue= HSV_BANDWIDTH * (float)(cur % grouping);
|
|
|
|
|
|
|
|
|
|
/* '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 */
|
|
|
|
|
hue += fac * HSV_BANDWIDTH;
|
|
|
|
|
if (hue > 1.0f) hue= fmod(hue, 1.0f);
|
|
|
|
|
|
2009-05-18 02:23:20 +00:00
|
|
|
/* saturation adjustments for more visible range */
|
|
|
|
|
if ((hue > 0.5f) && (hue < 0.8f)) sat= 0.5f;
|
|
|
|
|
else sat= 0.6f;
|
|
|
|
|
|
|
|
|
|
/* value is fixed at 1.0f, otherwise we cannot clearly see the curves... */
|
|
|
|
|
val= 1.0f;
|
2009-05-11 11:41:08 +00:00
|
|
|
|
|
|
|
|
/* finally, conver this to RGB colors */
|
|
|
|
|
hsv_to_rgb(hue, sat, val, out, out+1, out+2);
|
|
|
|
|
}
|