[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22305] branches/soc-2009-kazanbas: Added Object.find_armature() to find armature connected to object.

Arystanbek Dyussenov arystan.d at gmail.com
Sat Aug 8 13:33:34 CEST 2009


Revision: 22305
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22305
Author:   kazanbas
Date:     2009-08-08 13:33:34 +0200 (Sat, 08 Aug 2009)

Log Message:
-----------
Added Object.find_armature() to find armature connected to object. Previously this was BPyObject.getObjectArmature()

Modified Paths:
--------------
    branches/soc-2009-kazanbas/release/io/export_fbx.py
    branches/soc-2009-kazanbas/source/blender/editors/include/ED_mesh.h
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c

Modified: branches/soc-2009-kazanbas/release/io/export_fbx.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_fbx.py	2009-08-08 11:18:40 UTC (rev 22304)
+++ branches/soc-2009-kazanbas/release/io/export_fbx.py	2009-08-08 11:33:34 UTC (rev 22305)
@@ -118,26 +118,6 @@
 	
 	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 @@
 
 	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 @@
 							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 @@
 # - 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

Modified: branches/soc-2009-kazanbas/source/blender/editors/include/ED_mesh.h
===================================================================
--- branches/soc-2009-kazanbas/source/blender/editors/include/ED_mesh.h	2009-08-08 11:18:40 UTC (rev 22304)
+++ branches/soc-2009-kazanbas/source/blender/editors/include/ED_mesh.h	2009-08-08 11:33:34 UTC (rev 22305)
@@ -154,6 +154,9 @@
 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);
 

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-08-08 11:18:40 UTC (rev 22304)
+++ branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c	2009-08-08 11:33:34 UTC (rev 22305)
@@ -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 @@
 	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 @@
 	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 */





More information about the Bf-blender-cvs mailing list