From f6267e2a26cac8c7b30c7b165df1df54e9cec474 Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Fri, 19 Jun 2009 12:46:51 +0000 Subject: [PATCH] Moved struct DupliObject to DNA_object_types.h. Object.create_dupli_list now works ok. --- release/io/export_obj.py | 14 ++++++- source/blender/blenkernel/BKE_anim.h | 9 +---- source/blender/makesdna/DNA_object_types.h | 9 +++++ .../blender/makesrna/intern/rna_object_api.c | 38 +++++-------------- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/release/io/export_obj.py b/release/io/export_obj.py index 4354f9f9bb9..8b3bcfb26b3 100644 --- a/release/io/export_obj.py +++ b/release/io/export_obj.py @@ -41,7 +41,7 @@ class SCRIPT_OT_export_obj(bpy.types.Operator): 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 @@ class SCRIPT_OT_export_obj(bpy.types.Operator): # 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") diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index 5ea511738ad..091887a4eb7 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -39,14 +39,7 @@ struct PartEff; 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); diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index febf2fe59cd..445a948c5cb 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -230,6 +230,7 @@ typedef struct Object { 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 @@ typedef struct ObHook { 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; diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index e54c8c712c1..3944dd72cec 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -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 @@ void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports) PointerRNA obptr; PointerRNA dobptr; Scene *sce; - ListBase *lb; DupliObject *dob; PropertyRNA *prop; @@ -90,38 +89,27 @@ void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports) 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 @@ void rna_Object_free_duplilist(Object *ob, ReportList *reports) 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 @@ void RNA_api_object(StructRNA *srna) 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.");