[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21008] branches/soc-2009-kazanbas: Moved struct DupliObject to DNA_object_types.h.

Arystanbek Dyussenov arystan.d at gmail.com
Fri Jun 19 14:46:52 CEST 2009


Revision: 21008
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21008
Author:   kazanbas
Date:     2009-06-19 14:46:51 +0200 (Fri, 19 Jun 2009)

Log Message:
-----------
Moved struct DupliObject to DNA_object_types.h.
Object.create_dupli_list now works ok.

Modified Paths:
--------------
    branches/soc-2009-kazanbas/release/io/export_obj.py
    branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_anim.h
    branches/soc-2009-kazanbas/source/blender/makesdna/DNA_object_types.h
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c

Modified: branches/soc-2009-kazanbas/release/io/export_obj.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_obj.py	2009-06-19 12:45:08 UTC (rev 21007)
+++ branches/soc-2009-kazanbas/release/io/export_obj.py	2009-06-19 12:46:51 UTC (rev 21008)
@@ -41,7 +41,7 @@
 	def debug(self, message):
 		print("{0}: {1}".format(self.__class__.__name__, message))
 
-	def execute(self, context):
+	def execute_(self, context):
 		self.debug("exec")
 		self.debug("filename = " + self.filename)
 
@@ -56,6 +56,18 @@
 #		raise Exception("oops!")
 
 		return ('FINISHED',)
+
+	def execute(self, context):
+		self.debug("exec")
+		
+		act = context.active_object
+
+		act.create_dupli_list()
+		print("{0} has {1} dupli objects".format(act.name, len(act.dupli_list)))
+
+		act.free_dupli_list()
+
+		return ('FINISHED',)
 	
 	def invoke(self, context, event):
 		self.debug("invoke")

Modified: branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_anim.h
===================================================================
--- branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_anim.h	2009-06-19 12:45:08 UTC (rev 21007)
+++ branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_anim.h	2009-06-19 12:46:51 UTC (rev 21008)
@@ -39,14 +39,7 @@
 struct Scene;
 struct ListBase;
 
-typedef struct DupliObject {
-	struct DupliObject *next, *prev;
-	struct Object *ob;
-	unsigned int origlay;
-	int index, no_draw, type, animated;
-	float mat[4][4], omat[4][4];
-	float orco[3], uv[2];
-} DupliObject;
+#include "DNA_object_types.h"
 
 void free_path(struct Path *path);
 void calc_curvepath(struct Object *ob);

Modified: branches/soc-2009-kazanbas/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/soc-2009-kazanbas/source/blender/makesdna/DNA_object_types.h	2009-06-19 12:45:08 UTC (rev 21007)
+++ branches/soc-2009-kazanbas/source/blender/makesdna/DNA_object_types.h	2009-06-19 12:46:51 UTC (rev 21008)
@@ -230,6 +230,7 @@
 	int pad2;
 
 	ListBase gpulamp;		/* runtime, for lamps only */
+	ListBase *duplilist;	/* only for internal use by RNA API functions. To get dupli list, use object_duplilist instead */
 } Object;
 
 /* Warning, this is not used anymore because hooks are now modifiers */
@@ -250,6 +251,14 @@
 	float force;
 } ObHook;
 
+typedef struct DupliObject {
+	struct DupliObject *next, *prev;
+	struct Object *ob;
+	unsigned int origlay;
+	int index, no_draw, type, animated;
+	float mat[4][4], omat[4][4];
+	float orco[3], uv[2];
+} DupliObject;
 
 /* this work object is defined in object.c */
 extern Object workob;

Modified: branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c
===================================================================
--- branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c	2009-06-19 12:45:08 UTC (rev 21007)
+++ branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c	2009-06-19 12:46:51 UTC (rev 21008)
@@ -32,8 +32,6 @@
 #include "RNA_define.h"
 #include "RNA_types.h"
 
-#define OBJECT_API_PROP_DUPLILIST "dupli_list"
-
 #ifdef RNA_RUNTIME
 
 #include "BKE_customdata.h"
@@ -45,6 +43,8 @@
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 
+#define OBJECT_API_PROP_DUPLILIST "dupli_list"
+
 /* copied from init_render_mesh (render code) */
 Mesh *rna_Object_create_render_mesh(Object *ob, Scene *scene)
 {
@@ -75,7 +75,6 @@
 	PointerRNA obptr;
 	PointerRNA dobptr;
 	Scene *sce;
-	ListBase *lb;
 	DupliObject *dob;
 	PropertyRNA *prop;
 
@@ -90,38 +89,27 @@
 
 	if (!(prop= RNA_struct_find_property(&obptr, OBJECT_API_PROP_DUPLILIST))) {
 		// hint: all Objects will now have this property defined
-		prop= RNA_def_collection_runtime(obptr->type, OBJECT_API_PROP_DUPLILIST, "DupliObject", "Dupli list", "List of object's duplis");
+		prop= RNA_def_collection_runtime(obptr.type, OBJECT_API_PROP_DUPLILIST, "DupliObject", "Dupli list", "List of object's duplis");
 	}
 
 	RNA_property_collection_clear(&obptr, prop);
-	lb= object_duplilist(sce, ob);
+	ob->duplilist= object_duplilist(sce, ob);
 
-	for(dob= (DupliObject*)lb->first; dob; dob= dob->next) {
+	for(dob= (DupliObject*)ob->duplilist->first; dob; dob= dob->next) {
 		RNA_pointer_create(NULL, &RNA_Object, dob, &dobptr);
 		RNA_property_collection_add(&obptr, prop, &dobptr);
 		dob = dob->next;
 	}
 
-	/*
-	  Now we need to free duplilist with
+	/* ob->duplilist should now be freed with Object.free_duplilist */
 
-	  free_object_duplilist(lb);
-
-	  We can't to it here since DupliObjects are in use,
-	  but we also can't do it in another function since lb
-	  isn't stored...
-
-	  So we free lb, but not DupliObjects - these will have to be freed with Object.free_duplilist
-	 */
-
-	MEM_freeN(lb);
+	return *((CollectionPropertyRNA*)prop);
 }
 
 void rna_Object_free_duplilist(Object *ob, ReportList *reports)
 {
 	PointerRNA obptr;
 	PropertyRNA *prop;
-	CollectionPropertyIterator iter;
 
 	RNA_id_pointer_create(&ob->id, &obptr);
 
@@ -130,14 +118,10 @@
 		return;
 	}
 
-	/* free each allocated DupliObject */
-	RNA_property_collection_begin(&obptr, prop, &iter);
-	for(; iter.valid; RNA_property_collection_next(&iter)) {
-		MEM_freeN(iter.ptr.data);
-	}
-	RNA_property_collection_end(&iter);
-
 	RNA_property_collection_clear(&obptr, prop);
+
+	free_object_duplilist(ob->duplilist);
+	ob->duplilist= NULL;
 }
 
 #else
@@ -157,8 +141,6 @@
 	func= RNA_def_function(srna, "create_dupli_list", "rna_Object_create_duplilist");
 	RNA_def_function_ui_description(func, "Create a list of dupli objects for this object. When no longer needed, it should be freed with free_dupli_list.");
 	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
-	parm= RNA_def_collection(func, OBJECT_API_PROP_DUPLILIST, "DupliObject", "Dupli list", "List of objects's duplis.");
-	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "free_dupli_list", "rna_Object_free_duplilist");
 	RNA_def_function_ui_description(func, "Free the list of dupli objects.");





More information about the Bf-blender-cvs mailing list