[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20696] branches/soc-2009-aligorith/source /blender: NLA SoC: RNA wrapping for NLA Data

Joshua Leung aligorith at gmail.com
Sun Jun 7 08:49:06 CEST 2009


Revision: 20696
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20696
Author:   aligorith
Date:     2009-06-07 08:49:04 +0200 (Sun, 07 Jun 2009)

Log Message:
-----------
NLA SoC: RNA wrapping for NLA Data 

Most of the relevant properties have been wrapped. 
- There are still some properties I'm not sure about whether they should be exposed at all (which have been left out for now). Most of these are really internal flags which are used in a few select places.
- To maintain the integrity of the settings, I've included some custom code for a few of the setters (i.e. scale/end-frame) where changing one should result in a change in the other and vica-versa. 

Also, tweaked the wrapping for a few other types.

Another side effect of this commit is that I can now uncommented some code for using F-Curves to control the influence and time of the strips. These F-Curves would need to be specifically attached to the NLA-Strip they affect for now (TODO: I need to review this again...), and as such, cannot be used yet since there's no (end-user-accessible) way to do this :)

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c
    branches/soc-2009-aligorith/source/blender/makesrna/RNA_access.h
    branches/soc-2009-aligorith/source/blender/makesrna/intern/makesrna.c
    branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_animation.c
    branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_internal.h

Added Paths:
-----------
    branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c	2009-06-07 06:04:44 UTC (rev 20695)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c	2009-06-07 06:49:04 UTC (rev 20696)
@@ -657,16 +657,13 @@
 	
 	/* now strip's evaluate F-Curves for these settings (if applicable) */
 	if (strip->fcurves.first) {
-#if 0
 		PointerRNA strip_ptr;
-		FCurve *fcu;
 		
 		/* create RNA-pointer needed to set values */
 		RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr);
 		
 		/* execute these settings as per normal */
-		animsys_evaluate_fcurves(&actstrip_ptr, &strip->fcurves, NULL, ctime);
-#endif
+		animsys_evaluate_fcurves(&strip_ptr, &strip->fcurves, NULL, ctime);
 	}
 }
 

Modified: branches/soc-2009-aligorith/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/makesrna/RNA_access.h	2009-06-07 06:04:44 UTC (rev 20695)
+++ branches/soc-2009-aligorith/source/blender/makesrna/RNA_access.h	2009-06-07 06:49:04 UTC (rev 20696)
@@ -189,6 +189,8 @@
 extern StructRNA RNA_MusgraveTexture;
 extern StructRNA RNA_NandController;
 extern StructRNA RNA_NearSensor;
+extern StructRNA RNA_NlaTrack;
+extern StructRNA RNA_NlaStrip;
 extern StructRNA RNA_Node;
 extern StructRNA RNA_NodeTree;
 extern StructRNA RNA_NoiseTexture;

Modified: branches/soc-2009-aligorith/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/makesrna/intern/makesrna.c	2009-06-07 06:04:44 UTC (rev 20695)
+++ branches/soc-2009-aligorith/source/blender/makesrna/intern/makesrna.c	2009-06-07 06:49:04 UTC (rev 20696)
@@ -1794,6 +1794,7 @@
 	{"rna_mesh.c", RNA_def_mesh},
 	{"rna_meta.c", RNA_def_meta},
 	{"rna_modifier.c", RNA_def_modifier},
+	{"rna_nla.c", RNA_def_nla},
 	{"rna_nodetree.c", RNA_def_nodetree},
 	{"rna_object.c", RNA_def_object},
 	{"rna_object_force.c", RNA_def_object_force},

Modified: branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_animation.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_animation.c	2009-06-07 06:04:44 UTC (rev 20695)
+++ branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_animation.c	2009-06-07 06:49:04 UTC (rev 20696)
@@ -184,7 +184,7 @@
 	/* NLA */
 	prop= RNA_def_property(srna, "nla_tracks", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "nla_tracks", NULL);
-	RNA_def_property_struct_type(prop, "UnknownType"); // XXX!
+	RNA_def_property_struct_type(prop, "NlaTrack");
 	RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers).");
 	
 	/* Action */

Modified: branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_internal.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_internal.h	2009-06-07 06:04:44 UTC (rev 20695)
+++ branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_internal.h	2009-06-07 06:49:04 UTC (rev 20696)
@@ -139,6 +139,7 @@
 void RNA_def_mesh(struct BlenderRNA *brna);
 void RNA_def_meta(struct BlenderRNA *brna);
 void RNA_def_modifier(struct BlenderRNA *brna);
+void RNA_def_nla(struct BlenderRNA *brna);
 void RNA_def_nodetree(struct BlenderRNA *brna);
 void RNA_def_object(struct BlenderRNA *brna);
 void RNA_def_object_force(struct BlenderRNA *brna);

Added: branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c	                        (rev 0)
+++ branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c	2009-06-07 06:49:04 UTC (rev 20696)
@@ -0,0 +1,329 @@
+/**
+ * $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.
+ *
+ * Contributor(s): Blender Foundation (2009), Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+
+#include "RNA_define.h"
+#include "RNA_types.h"
+
+#include "rna_internal.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_action_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#ifdef RNA_RUNTIME
+
+#include <stdio.h>
+#include <math.h>
+
+static void rna_NlaStrip_start_frame_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	CLAMP(value, 1, data->end);
+	data->start= value;
+}
+
+static void rna_NlaStrip_end_frame_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	float len, actlen;
+	
+	/* clamp value to lie within valid limits - must not have zero or negative length strip */
+	CLAMP(value, data->start+0.1f, MAXFRAME);
+	data->end= value;
+	
+	/* calculate the lengths the strip and its action (if applicable) */
+	len= data->end - data->start;
+	actlen= data->actend - data->actstart;
+	if (IS_EQ(actlen, 0.0f)) actlen= 1.0f;
+	
+	/* now, adjust the 'scale' setting to reflect this (so that this change can be valid) */
+	data->scale= len / ((actlen) * data->repeat);
+}
+
+static void rna_NlaStrip_scale_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	float actlen, mapping;
+	
+	/* set scale value */
+	CLAMP(value, 0.0001f, 1000.0f); /* NOTE: these need to be synced with the values in the property definition in rna_def_nlastrip() */
+	data->scale= value;
+	
+	/* calculate existing factors */
+	actlen= data->actend - data->actstart;
+	if (IS_EQ(actlen, 0.0f)) actlen= 1.0f;
+	mapping= data->scale * data->repeat;
+	
+	/* adjust endpoint of strip in response to this */
+	if (IS_EQ(mapping, 0.0f) == 0)
+		data->end = (actlen * mapping) + data->start; 
+	else
+		printf("NlaStrip Set Scale Error (in RNA): Scale = %0.4f, Repeat = %0.4f \n", data->scale, data->repeat);
+}
+
+static void rna_NlaStrip_blend_in_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	float len;
+	
+	/* blend-in is limited to the length of the strip, and also cannot overlap with blendout */
+	len= (data->end - data->start) - data->blendout;
+	CLAMP(value, 0, len);
+	
+	data->blendin= value;
+}
+
+static void rna_NlaStrip_blend_out_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	float len;
+	
+	/* blend-out is limited to the length of the strip */
+	len= (data->end - data->start);
+	CLAMP(value, 0, len);
+	
+	/* it also cannot overlap with blendin */
+	if ((len - value) < data->blendin)
+		value= len - data->blendin;
+	
+	data->blendout= value;
+}
+
+static void rna_NlaStrip_action_start_frame_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	CLAMP(value, 1, data->actend);
+	data->actstart= value;
+}
+
+static void rna_NlaStrip_action_end_frame_set(PointerRNA *ptr, float value)
+{
+	NlaStrip *data= (NlaStrip*)ptr->data;
+	CLAMP(value, data->actstart, MAXFRAME);
+	data->actend= value;
+}
+
+#else
+
+void rna_def_nlastrip(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+		/* enum defs */
+	static EnumPropertyItem prop_type_items[] = {
+		{NLASTRIP_TYPE_CLIP, "CLIP", "Action Clip", "NLA Strip references some Action."},
+		{NLASTRIP_TYPE_TRANSITION, "TRANSITION", "Transition", "NLA Strip 'transitions' between adjacent strips."},
+		{0, NULL, NULL, NULL}};
+	static EnumPropertyItem prop_mode_blend_items[] = {
+		{NLASTRIP_MODE_BLEND, "BLEND", "Blend", "Results of strip and accumulated results are combined in ratio governed by influence."},
+		{NLASTRIP_MODE_ADD, "ADD", "Add", "Weighted result of strip is added to the accumlated results."},
+		{NLASTRIP_MODE_SUBTRACT, "SUBTRACT", "Subtract", "Weighted result of strip is removed from the accumlated results."},
+		{NLASTRIP_MODE_MULTIPLY, "MULITPLY", "Multiply", "Weighted result of strip is multiplied with the accumlated results."},
+		{0, NULL, NULL, NULL}};
+	static EnumPropertyItem prop_mode_extend_items[] = {
+		{NLASTRIP_EXTEND_NOTHING, "NOTHING", "Nothing", "Strip has no influence past its extents."},
+		{NLASTRIP_EXTEND_HOLD, "HOLD", "Hold", "Hold the first frame if no previous strips in track, and always hold last frame."},
+		{NLASTRIP_EXTEND_HOLD_FORWARD, "HOLD_FORWARD", "Hold Forward", "Only hold last frame."},
+		{0, NULL, NULL, NULL}};
+	
+	/* struct definition */
+	srna= RNA_def_struct(brna, "NlaStrip", NULL);
+	RNA_def_struct_ui_text(srna, "NLA Strip", "A container referencing an existing Action.");
+	//RNA_def_struct_ui_icon(srna, ICON_ACTION);
+	
+	/* Enums */
+	prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "type");
+	RNA_def_property_enum_items(prop, prop_type_items);
+	RNA_def_property_ui_text(prop, "Type", "Type of NLA Strip.");
+	
+	prop= RNA_def_property(srna, "extrapolation", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "extendmode");
+	RNA_def_property_enum_items(prop, prop_mode_extend_items);
+	RNA_def_property_ui_text(prop, "Extrapolation", "Action to take for gaps past the strip extents.");
+	
+	prop= RNA_def_property(srna, "blending", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "blendmode");
+	RNA_def_property_enum_items(prop, prop_mode_blend_items);
+	RNA_def_property_ui_text(prop, "Blending", "Method used for combining strip's result with accumulated result.");
+	
+	/* Strip extents */
+	prop= RNA_def_property(srna, "start_frame", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "start");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list