Blender V2.61 - r43446

rna_animviz.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Blender Foundation (2010), Joshua Leung
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include <stdlib.h>
00029 
00030 #include "RNA_define.h"
00031 
00032 #include "rna_internal.h"
00033 
00034 #include "DNA_anim_types.h"
00035 #include "DNA_action_types.h"
00036 #include "DNA_scene_types.h"
00037 
00038 #include "MEM_guardedalloc.h"
00039 
00040 #include "WM_types.h"
00041 
00042 #ifdef RNA_RUNTIME
00043 
00044 static PointerRNA rna_AnimViz_onion_skinning_get(PointerRNA *ptr)
00045 {
00046     return rna_pointer_inherit_refine(ptr, &RNA_AnimVizOnionSkinning, ptr->data);
00047 }
00048 
00049 static PointerRNA rna_AnimViz_motion_paths_get(PointerRNA *ptr)
00050 {
00051     return rna_pointer_inherit_refine(ptr, &RNA_AnimVizMotionPaths, ptr->data);
00052 }
00053 
00054 static void rna_AnimViz_ghost_start_frame_set(PointerRNA *ptr, int value)
00055 {
00056     bAnimVizSettings *data= (bAnimVizSettings*)ptr->data;
00057     
00058     CLAMP(value, 1, data->ghost_ef);
00059     data->ghost_sf= value;
00060 }
00061 
00062 static void rna_AnimViz_ghost_end_frame_set(PointerRNA *ptr, int value)
00063 {
00064     bAnimVizSettings *data= (bAnimVizSettings*)ptr->data;
00065     
00066     CLAMP(value, data->ghost_sf, (int)(MAXFRAMEF/2));
00067     data->ghost_ef= value;
00068 }
00069 
00070 static void rna_AnimViz_path_start_frame_set(PointerRNA *ptr, int value)
00071 {
00072     bAnimVizSettings *data= (bAnimVizSettings*)ptr->data;
00073     
00074     CLAMP(value, 1, data->path_ef-1);
00075     data->path_sf= value;
00076 }
00077 
00078 static void rna_AnimViz_path_end_frame_set(PointerRNA *ptr, int value)
00079 {
00080     bAnimVizSettings *data= (bAnimVizSettings*)ptr->data;
00081     
00082     // XXX: watchit! Path Start > MAXFRAME/2 could be a problem...
00083     CLAMP(value, data->path_sf+1, (int)(MAXFRAMEF/2));
00084     data->path_ef= value;
00085 }
00086 
00087 #else
00088 
00089 void rna_def_motionpath_common(StructRNA *srna)
00090 {
00091     PropertyRNA *prop;
00092     
00093     prop= RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
00094     RNA_def_property_pointer_sdna(prop, NULL, "mpath");
00095     RNA_def_property_ui_text(prop, "Motion Path", "Motion Path for this element");  
00096 }
00097 
00098 static void rna_def_animviz_motionpath_vert(BlenderRNA *brna)
00099 {
00100     StructRNA *srna;
00101     PropertyRNA *prop;
00102     
00103     srna= RNA_def_struct(brna, "MotionPathVert", NULL);
00104     RNA_def_struct_sdna(srna, "bMotionPathVert");
00105     RNA_def_struct_ui_text(srna, "Motion Path Cache Point", "Cached location on path");
00106     
00107     prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
00108     RNA_def_property_array(prop, 3);
00109     RNA_def_property_ui_text(prop, "Coordinates", "");
00110     
00111     prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
00112     RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_VERT_SEL);
00113     RNA_def_property_ui_text(prop, "Select", "Path point is selected for editing");
00114 }
00115 
00116 static void rna_def_animviz_motion_path(BlenderRNA *brna)
00117 {
00118     StructRNA *srna;
00119     PropertyRNA *prop;
00120     
00121     srna= RNA_def_struct(brna, "MotionPath", NULL);
00122     RNA_def_struct_sdna(srna, "bMotionPath");
00123     RNA_def_struct_ui_text(srna, "Motion Path", "Cache of the worldspace positions of an element over a frame range");
00124     
00125     /* Collections */
00126     prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
00127     RNA_def_property_collection_sdna(prop, NULL, "points", "length");
00128     RNA_def_property_struct_type(prop, "MotionPathVert");
00129     RNA_def_property_ui_text(prop, "Motion Path Points", "Cached positions per frame");
00130     
00131     /* Playback Ranges */
00132     prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
00133     RNA_def_property_int_sdna(prop, NULL, "start_frame");
00134     RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00135     RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of the stored range");
00136     
00137     prop= RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
00138     RNA_def_property_int_sdna(prop, NULL, "end_frame");
00139     RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00140     RNA_def_property_ui_text(prop, "End Frame", "End frame of the stored range");
00141     
00142     prop= RNA_def_property(srna, "length", PROP_INT, PROP_TIME);
00143     RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00144     RNA_def_property_ui_text(prop, "Length", "Number of frames cached");
00145     
00146     /* Settings */
00147     prop= RNA_def_property(srna, "use_bone_head", PROP_BOOLEAN, PROP_NONE);
00148     RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_BHEAD);
00149     RNA_def_property_clear_flag(prop, PROP_EDITABLE); // xxx
00150     RNA_def_property_ui_text(prop, "Use Bone Heads", "For PoseBone paths, use the bone head location when calculating this path");
00151     
00152     prop= RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE);
00153     RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_EDIT);
00154     RNA_def_property_ui_text(prop, "Edit Path", "Path is being edited");
00155 }
00156 
00157 /* --- */
00158 
00159 static void rna_def_animviz_ghosts(BlenderRNA *brna)
00160 {
00161     StructRNA *srna;
00162     PropertyRNA *prop;
00163     
00164     static const EnumPropertyItem prop_type_items[] = {
00165         {GHOST_TYPE_NONE, "NONE", 0, "No Ghosts", "Do not show any ghosts"},
00166         {GHOST_TYPE_ACFRA, "CURRENT_FRAME", 0, "Around Current Frame", "Show ghosts from around the current frame"},
00167         {GHOST_TYPE_RANGE, "RANGE", 0, "In Range", "Show ghosts for the specified frame range"},
00168         {GHOST_TYPE_KEYS, "KEYS", 0, "On Keyframes", "Show ghosts on keyframes"},
00169         {0, NULL, 0, NULL, NULL}};
00170     
00171     
00172     srna= RNA_def_struct(brna, "AnimVizOnionSkinning", NULL);
00173     RNA_def_struct_sdna(srna, "bAnimVizSettings");
00174     RNA_def_struct_nested(brna, srna, "AnimViz");
00175     RNA_def_struct_ui_text(srna, "Onion Skinning Settings", "Onion Skinning settings for animation visualisation");
00176 
00177     /* Enums */
00178     prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00179     RNA_def_property_enum_sdna(prop, NULL, "ghost_type");
00180     RNA_def_property_enum_items(prop, prop_type_items);
00181     RNA_def_property_ui_text(prop, "Type", "Method used for determining what ghosts get drawn");
00182     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00183     
00184     /* Settings */
00185     prop= RNA_def_property(srna, "show_only_selected", PROP_BOOLEAN, PROP_NONE);
00186     RNA_def_property_boolean_sdna(prop, NULL, "ghost_flag", GHOST_FLAG_ONLYSEL);
00187     RNA_def_property_ui_text(prop, "On Selected Bones Only", "For Pose-Mode drawing, only draw ghosts for selected bones");
00188     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00189     
00190     prop= RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
00191     RNA_def_property_int_sdna(prop, NULL, "ghost_step");
00192     RNA_def_property_range(prop, 1, 20);
00193     RNA_def_property_ui_text(prop, "Frame Step", "Number of frames between ghosts shown (not for 'On Keyframes' Onion-skinning method)");
00194     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00195     
00196     /* Playback Ranges */
00197     prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
00198     RNA_def_property_int_sdna(prop, NULL, "ghost_sf");
00199     RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_ghost_start_frame_set", NULL);
00200     RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of range of Ghosts to display (not for 'Around Current Frame' Onion-skinning method)");
00201     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00202     
00203     prop= RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
00204     RNA_def_property_int_sdna(prop, NULL, "ghost_ef");
00205     RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_ghost_end_frame_set", NULL);
00206     RNA_def_property_ui_text(prop, "End Frame", "End frame of range of Ghosts to display (not for 'Around Current Frame' Onion-skinning method)");
00207     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00208     
00209     /* Around Current Ranges */
00210     prop= RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
00211     RNA_def_property_int_sdna(prop, NULL, "ghost_bc");
00212     RNA_def_property_range(prop, 0, 30);
00213     RNA_def_property_ui_text(prop, "Before Current", "Number of frames to show before the current frame (only for 'Around Current Frame' Onion-skinning method)");
00214     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00215     
00216     prop= RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
00217     RNA_def_property_int_sdna(prop, NULL, "ghost_ac");
00218     RNA_def_property_range(prop, 0, 30);
00219     RNA_def_property_ui_text(prop, "After Current", "Number of frames to show after the current frame (only for 'Around Current Frame' Onion-skinning method)");
00220     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00221 }
00222 
00223 static void rna_def_animviz_paths(BlenderRNA *brna)
00224 {
00225     StructRNA *srna;
00226     PropertyRNA *prop;
00227     
00228     static const EnumPropertyItem prop_type_items[]= {
00229         {MOTIONPATH_TYPE_ACFRA, "CURRENT_FRAME", 0, "Around Frame", "Display Paths of poses within a fixed number of frames around the current frame"},
00230         {MOTIONPATH_TYPE_RANGE, "RANGE", 0, "In Range", "Display Paths of poses within specified range"},
00231         {0, NULL, 0, NULL, NULL}};
00232     static const EnumPropertyItem prop_location_items[]= {
00233         {MOTIONPATH_BAKE_HEADS, "HEADS", 0, "Heads", "Calculate bone paths from heads"},
00234         {0, "TAILS", 0, "Tails", "Calculate bone paths from tails"},
00235         {0, NULL, 0, NULL, NULL}};
00236     
00237     srna= RNA_def_struct(brna, "AnimVizMotionPaths", NULL);
00238     RNA_def_struct_sdna(srna, "bAnimVizSettings");
00239     RNA_def_struct_nested(brna, srna, "AnimViz");
00240     RNA_def_struct_ui_text(srna, "Motion Path Settings", "Motion Path settings for animation visualisation");
00241     
00242     /* Enums */
00243     prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00244     RNA_def_property_enum_sdna(prop, NULL, "path_type");
00245     RNA_def_property_enum_items(prop, prop_type_items);
00246     RNA_def_property_ui_text(prop, "Paths Type", "Type of range to show for Motion Paths");
00247     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00248     
00249     prop= RNA_def_property(srna, "bake_location", PROP_ENUM, PROP_NONE);
00250     RNA_def_property_enum_bitflag_sdna(prop, NULL, "path_bakeflag");
00251     RNA_def_property_enum_items(prop, prop_location_items);
00252     RNA_def_property_ui_text(prop, "Bake Location", "When calculating Bone Paths, use Head or Tips");
00253     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00254     
00255     /* Settings */
00256     prop= RNA_def_property(srna, "show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
00257     RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_FNUMS);
00258     RNA_def_property_ui_text(prop, "Show Frame Numbers", "Show frame numbers on Motion Paths");
00259     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00260     
00261     prop= RNA_def_property(srna, "show_keyframe_highlight", PROP_BOOLEAN, PROP_NONE);
00262     RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFRAS);
00263     RNA_def_property_ui_text(prop, "Highlight Keyframes", "Emphasize position of keyframes on Motion Paths");
00264     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00265     
00266     prop= RNA_def_property(srna, "show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
00267     RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFNOS);
00268     RNA_def_property_ui_text(prop, "Show Keyframe Numbers", "Show frame numbers of Keyframes on Motion Paths");
00269     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00270     
00271     prop= RNA_def_property(srna, "show_keyframe_action_all", PROP_BOOLEAN, PROP_NONE);
00272     RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFACT);
00273     RNA_def_property_ui_text(prop, "All Action Keyframes", "For bone motion paths, search whole Action for keyframes instead of in group with matching name only (is slower)");
00274     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00275     
00276     prop= RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
00277     RNA_def_property_int_sdna(prop, NULL, "path_step");
00278     RNA_def_property_range(prop, 1, 100);
00279     RNA_def_property_ui_text(prop, "Frame Step", "Number of frames between paths shown (not for 'On Keyframes' Onion-skinning method)");
00280     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00281     
00282     
00283     /* Playback Ranges */
00284     prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
00285     RNA_def_property_int_sdna(prop, NULL, "path_sf");
00286     RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_start_frame_set", NULL);
00287     RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of range of paths to display/calculate (not for 'Around Current Frame' Onion-skinning method)");
00288     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00289     
00290     prop= RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
00291     RNA_def_property_int_sdna(prop, NULL, "path_ef");
00292     RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_end_frame_set", NULL);
00293     RNA_def_property_ui_text(prop, "End Frame", "End frame of range of paths to display/calculate (not for 'Around Current Frame' Onion-skinning method)");
00294     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00295     
00296     /* Around Current Ranges */
00297     prop= RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
00298     RNA_def_property_int_sdna(prop, NULL, "path_bc");
00299     RNA_def_property_range(prop, 1, MAXFRAMEF/2);
00300     RNA_def_property_ui_text(prop, "Before Current", "Number of frames to show before the current frame (only for 'Around Current Frame' Onion-skinning method)");
00301     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00302     
00303     prop= RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
00304     RNA_def_property_int_sdna(prop, NULL, "path_ac");
00305     RNA_def_property_range(prop, 1, MAXFRAMEF/2);
00306     RNA_def_property_ui_text(prop, "After Current", "Number of frames to show after the current frame (only for 'Around Current Frame' Onion-skinning method)");
00307     RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
00308 }
00309 
00310 /* --- */
00311 
00312 void rna_def_animviz_common(StructRNA *srna)
00313 {
00314     PropertyRNA *prop;
00315     
00316     prop= RNA_def_property(srna, "animation_visualisation", PROP_POINTER, PROP_NONE);
00317     RNA_def_property_flag(prop, PROP_NEVER_NULL);
00318     RNA_def_property_pointer_sdna(prop, NULL, "avs");
00319     RNA_def_property_ui_text(prop, "Animation Visualisation", "Animation data for this datablock"); 
00320 }
00321 
00322 static void rna_def_animviz(BlenderRNA *brna)
00323 {
00324     StructRNA *srna;
00325     PropertyRNA *prop;
00326     
00327     srna= RNA_def_struct(brna, "AnimViz", NULL);
00328     RNA_def_struct_sdna(srna, "bAnimVizSettings");
00329     RNA_def_struct_ui_text(srna, "Animation Visualisation", "Settings for the visualisation of motion");
00330     
00331     /* onion-skinning settings (nested struct) */
00332     prop= RNA_def_property(srna, "onion_skin_frames", PROP_POINTER, PROP_NONE);
00333     RNA_def_property_flag(prop, PROP_NEVER_NULL);
00334     RNA_def_property_struct_type(prop, "AnimVizOnionSkinning");
00335     RNA_def_property_pointer_funcs(prop, "rna_AnimViz_onion_skinning_get", NULL, NULL, NULL);
00336     RNA_def_property_ui_text(prop, "Onion Skinning", "Onion Skinning (ghosting) settings for visualisation");
00337     
00338     /* motion path settings (nested struct) */
00339     prop= RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
00340     RNA_def_property_flag(prop, PROP_NEVER_NULL);
00341     RNA_def_property_struct_type(prop, "AnimVizMotionPaths");
00342     RNA_def_property_pointer_funcs(prop, "rna_AnimViz_motion_paths_get", NULL, NULL, NULL);
00343     RNA_def_property_ui_text(prop, "Motion Paths", "Motion Path settings for visualisation");
00344 }
00345 
00346 /* --- */
00347 
00348 void RNA_def_animviz(BlenderRNA *brna)
00349 {
00350     rna_def_animviz(brna);
00351         rna_def_animviz_ghosts(brna);
00352         rna_def_animviz_paths(brna);
00353         
00354     rna_def_animviz_motion_path(brna);
00355     rna_def_animviz_motionpath_vert(brna);
00356 }
00357 
00358 #endif