From 8fa528cef8faa4f5ce2f6ff4f6e2f5b08709d08e Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Sat, 8 Aug 2009 11:33:34 +0000 Subject: [PATCH] Added Object.find_armature() to find armature connected to object. Previously this was BPyObject.getObjectArmature() --- release/io/export_fbx.py | 48 +------------------ source/blender/editors/include/ED_mesh.h | 3 ++ .../blender/makesrna/intern/rna_object_api.c | 30 ++++++++++++ 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/release/io/export_fbx.py b/release/io/export_fbx.py index 5bb169a9849..2a3ea5fc30e 100644 --- a/release/io/export_fbx.py +++ b/release/io/export_fbx.py @@ -118,26 +118,6 @@ def copy_images(dest_dir, textures): print('\tCopied %d images' % copyCount) -def BPyObject_getObjectArmature(ob): - ''' - This returns the first armature the mesh uses. - remember there can be more then 1 armature but most people dont do that. - ''' - if ob.type != 'MESH': - return None - - arm = ob.parent - if arm and arm.type == 'ARMATURE' and ob.parent_type == 'ARMATURE': - return arm - - for m in ob.modifiers: - if m.type== 'ARMATURE': - arm = m.object - if arm: - return arm - - return None - # I guess FBX uses degrees instead of radians (Arystan). # Call this function just before writing to FBX. def eulerRadToDeg(eul): @@ -298,30 +278,6 @@ def BPyMesh_meshWeight2List(ob): return groupNames, vWeightList - -def BPyMesh_meshWeight2Dict(me, ob): - ''' Takes a mesh and return its group names and a list of dicts, one dict per vertex. - using the group as a key and a float value for the weight. - These 2 lists can be modified and then used with dict2MeshWeight to apply the changes. - ''' - - vWeightDict= [dict() for i in range(len(me.verts))] # Sync with vertlist. - - # Clear the vert group. - groupNames= [g.name for g in ob.vertex_groups] -# groupNames= me.getVertGroupNames() - - for group in groupNames: - for vert_index, weight in me.getVertsFromGroup(group, 1): # (i,w) tuples. - vWeightDict[vert_index][group]= weight - - # removed this because me may be copying teh vertex groups. - #for group in groupNames: - # me.removeVertGroup(group) - - return groupNames, vWeightDict - - def meshNormalizedWeights(me): try: # account for old bad BPyMesh groupNames, vWeightList = BPyMesh_meshWeight2List(me) @@ -2199,7 +2155,7 @@ def write(filename, batch_objects = None, \ materials[None, None] = None if EXP_ARMATURE: - armob = BPyObject_getObjectArmature(ob) + armob = ob.find_armature() blenParentBoneName = None # parent bone - special case @@ -3482,7 +3438,7 @@ bpy.ops.add(EXPORT_OT_fbx) # - Draw.PupMenu alternative in 2.5?, temporarily replaced PupMenu with print # - get rid of cleanName somehow # + fixed: isinstance(inst, bpy.types.*) doesn't work on RNA objects: line 565 -# - get rid of BPyObject_getObjectArmature, move it in RNA? +# + get rid of BPyObject_getObjectArmature, move it in RNA? # - BATCH_ENABLE and BATCH_GROUP options: line 327 # - implement all BPyMesh_* used here with RNA # - getDerivedObjects is not fully replicated with .dupli* funcs diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 0face00f82b..cceebeadc96 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -154,6 +154,9 @@ void EM_reveal_mesh(struct EditMesh *em); void EM_select_by_material(struct EditMesh *em, int index); void EM_deselect_by_material(struct EditMesh *em, int index); +/* editmesh_tools.c */ +void convert_to_triface(struct EditMesh *em, int direction); + /* editface.c */ struct MTFace *EM_get_active_mtface(struct EditMesh *em, struct EditFace **act_efa, struct MCol **mcol, int sloppy); diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 881c2bdf549..8192801d9fb 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -63,6 +63,7 @@ #include "DNA_scene_types.h" #include "DNA_meshdata_types.h" #include "DNA_curve_types.h" +#include "DNA_modifier_types.h" #include "MEM_guardedalloc.h" @@ -309,6 +310,29 @@ static void rna_Object_make_display_list(Object *ob, bContext *C) DAG_object_flush_update(sce, ob, OB_RECALC_DATA); } +static Object *rna_Object_find_armature(Object *ob) +{ + Object *ob_arm = NULL; + + if (ob->type != OB_MESH) return NULL; + + if (ob->parent && ob->partype == PARSKEL && ob->parent->type == OB_ARMATURE) { + ob_arm = ob->parent; + } + else { + ModifierData *mod = (ModifierData*)ob->modifiers.first; + while (mod) { + if (mod->type == eModifierType_Armature) { + ob_arm = ((ArmatureModifierData*)mod)->object; + } + + mod = mod->next; + } + } + + return ob_arm; +} + /* static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex, float weight, int assignmode) { @@ -409,6 +433,12 @@ void RNA_api_object(StructRNA *srna) parm= RNA_def_enum(func, "type", assign_mode_items, 0, "", "Vertex assign mode."); RNA_def_property_flag(parm, PROP_REQUIRED); + /* Armature */ + func= RNA_def_function(srna, "find_armature", "rna_Object_find_armature"); + RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier."); + parm= RNA_def_pointer(func, "ob_arm", "Object", "", "Armature object influencing this object or NULL."); + RNA_def_function_return(func, parm); + /* DAG */ func= RNA_def_function(srna, "make_display_list", "rna_Object_make_display_list"); RNA_def_function_ui_description(func, "Update object's display data."); /* XXX describe better */