[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21627] branches/soc-2009-kazanbas: - replaced Object.create_mesh body with 2.4x API's Mesh. createFromObject code to also support curves, surfaces and metaballs.

Arystanbek Dyussenov arystan.d at gmail.com
Thu Jul 16 15:19:43 CEST 2009


Revision: 21627
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21627
Author:   kazanbas
Date:     2009-07-16 15:19:43 +0200 (Thu, 16 Jul 2009)

Log Message:
-----------
- replaced Object.create_mesh body with 2.4x API's Mesh.createFromObject code to also support curves, surfaces and metaballs.
- replaced Object.dag_update with Object.make_display_list, which copies old API's Object.makeDisplayList

Modified Paths:
--------------
    branches/soc-2009-kazanbas/release/io/export_fbx.py
    branches/soc-2009-kazanbas/release/io/export_obj.py
    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-07-16 11:05:16 UTC (rev 21626)
+++ branches/soc-2009-kazanbas/release/io/export_fbx.py	2009-07-16 13:19:43 UTC (rev 21627)
@@ -2019,41 +2019,60 @@
 		# This is needed so applying modifiers dosnt apply the armature deformation, its also needed
 		# ...so mesh objects return their rest worldspace matrix when bone-parents are exported as weighted meshes.
 		# set every armature to its rest, backup the original values so we done mess up the scene
-		ob_arms_orig_rest = [arm.restPosition for arm in bpy.data.armatures]
+		ob_arms_orig_rest = [arm.rest_position for arm in bpy.data.armatures]
+# 		ob_arms_orig_rest = [arm.restPosition for arm in bpy.data.armatures]
 		
 		for arm in bpy.data.armatures:
-			arm.restPosition = True
+			arm.rest_position = True
+# 			arm.restPosition = True
 		
 		if ob_arms_orig_rest:
 			for ob_base in bpy.data.objects:
 				#if ob_base.type == 'Armature':
-				ob_base.makeDisplayList()
+				ob_base.make_display_list()
+# 				ob_base.makeDisplayList()
 					
 			# This causes the makeDisplayList command to effect the mesh
-			Blender.Set('curframe', Blender.Get('curframe'))
+			sce.set_frame(sce.current_frame)
+# 			Blender.Set('curframe', Blender.Get('curframe'))
 			
 	
 	for ob_base in tmp_objects:
-		for ob, mtx in BPyObject.getDerivedObjects(ob_base):
-			#for ob in [ob_base,]:
+
+		# ignore dupli children
+		if ob_base.parent and ob_base.parent.dupli_type != 'NONE':
+			continue
+
+		obs = [(ob_base, ob_base.matrix)]
+		if ob_base.dupli_type != 'NONE':
+			ob_base.create_dupli_list()
+			obs = [(dob.object, dob.matrix) for dob in ob_base.dupli_list]
+
+		for ob, mtx in obs:
+# 		for ob, mtx in BPyObject.getDerivedObjects(ob_base):
 			tmp_ob_type = ob.type
-			if tmp_ob_type == 'Camera':
+			if tmp_ob_type == 'CAMERA':
+# 			if tmp_ob_type == 'Camera':
 				if EXP_CAMERA:
 					ob_cameras.append(my_object_generic(ob, mtx))
-			elif tmp_ob_type == 'Lamp':
+			elif tmp_ob_type == 'LAMP':
+# 			elif tmp_ob_type == 'Lamp':
 				if EXP_LAMP:
 					ob_lights.append(my_object_generic(ob, mtx))
-			elif tmp_ob_type == 'Armature':
+			elif tmp_ob_type == 'ARMATURE':
+# 			elif tmp_ob_type == 'Armature':
 				if EXP_ARMATURE:
 					# TODO - armatures dont work in dupligroups!
 					if ob not in ob_arms: ob_arms.append(ob)
 					# ob_arms.append(ob) # replace later. was "ob_arms.append(sane_obname(ob), ob)"
-			elif tmp_ob_type == 'Empty':
+			elif tmp_ob_type == 'EMPTY':
+# 			elif tmp_ob_type == 'Empty':
 				if EXP_EMPTY:
 					ob_null.append(my_object_generic(ob, mtx))
 			elif EXP_MESH:
 				origData = True
-				if tmp_ob_type != 'Mesh':
+				if tmp_ob_type != 'MESH':
+# 				if tmp_ob_type != 'Mesh':
 					me = bpy.data.meshes.new()
 					try:	me.getFromObject(ob)
 					except:	me = None
@@ -2171,8 +2190,9 @@
 			
 		if ob_arms_orig_rest:
 			for ob_base in bpy.data.objects:
-				if ob_base.type == 'Armature':
-					ob_base.dag_update()
+				if ob_base.type == 'ARMATURE':
+# 				if ob_base.type == 'Armature':
+					ob_base.make_display_list()
 # 					ob_base.makeDisplayList()
 			# This causes the makeDisplayList command to effect the mesh
 			sce.set_frame(sce.current_frame)
@@ -3322,6 +3342,7 @@
 # - 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
 
 # TODO
 

Modified: branches/soc-2009-kazanbas/release/io/export_obj.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_obj.py	2009-07-16 11:05:16 UTC (rev 21626)
+++ branches/soc-2009-kazanbas/release/io/export_obj.py	2009-07-16 13:19:43 UTC (rev 21627)
@@ -380,11 +380,6 @@
 	# Get all meshes
 	for ob_main in objects:
 
-		if ob_main.dupli_type != 'NONE':
-			# XXX
-			print('creating dupli_list on', ob_main.name)
-			ob_main.create_dupli_list()
-
 		# ignore dupli children
 		if ob_main.parent and ob_main.parent.dupli_type != 'NONE':
 			# XXX
@@ -393,6 +388,10 @@
 
 		obs = []
 		if ob_main.dupli_type != 'NONE':
+			# XXX
+			print('creating dupli_list on', ob_main.name)
+			ob_main.create_dupli_list()
+			
 			obs = [(dob.object, dob.matrix) for dob in ob_main.dupli_list]
 
 			# XXX debug print

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-07-16 11:05:16 UTC (rev 21626)
+++ branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object_api.c	2009-07-16 13:19:43 UTC (rev 21627)
@@ -40,62 +40,190 @@
 
 #include "ED_mesh.h"
 
-/* parameter to rna_Object_create_mesh */
-typedef enum CreateMeshType {
-	CREATE_MESH_PREVIEW = 0,
-	CREATE_MESH_RENDER = 1
-} CreateMeshType;
-
 #ifdef RNA_RUNTIME
 
+#include "BKE_main.h"
+#include "BKE_global.h"
+#include "BKE_context.h"
+#include "BKE_report.h"
+#include "BKE_object.h"
+#include "BKE_mesh.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_customdata.h"
-#include "BKE_DerivedMesh.h"
 #include "BKE_anim.h"
-#include "BKE_report.h"
 #include "BKE_depsgraph.h"
+#include "BKE_displist.h"
+#include "BKE_font.h"
+#include "BKE_mball.h"
 
+#include "BLI_arithb.h"
+
 #include "DNA_mesh_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_curve_types.h"
 
-#include "BLI_arithb.h"
+#include "MEM_guardedalloc.h"
 
-/* copied from init_render_mesh (render code) */
-static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports, int type)
+/* copied from Mesh_getFromObject and adapted to RNA interface */
+/* settings: 0 - preview, 1 - render */
+static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports, int apply_modifiers, int settings)
 {
-	/* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */
-	CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter,
-										   for example, needs CD_MASK_MDEFORMVERT */
-	DerivedMesh *dm;
-	Mesh *me;
-	Scene *sce;
+	Mesh *tmpmesh;
+	Curve *tmpcu = NULL;
+	Object *tmpobj = NULL;
+	int render = settings, i;
+	int cage = !apply_modifiers;
+	Scene *sce = CTX_data_scene(C);
 
-	sce= CTX_data_scene(C);
+	/* perform the mesh extraction based on type */
+ 	switch (ob->type) {
+ 	case OB_FONT:
+ 	case OB_CURVE:
+ 	case OB_SURF:
+
+		/* copies object and modifiers (but not the data) */
+		tmpobj= copy_object(ob);
+		tmpcu = (Curve *)tmpobj->data;
+		tmpcu->id.us--;
+
+		/* if getting the original caged mesh, delete object modifiers */
+		if( cage )
+			object_free_modifiers(tmpobj);
+
+		/* copies the data */
+		tmpobj->data = copy_curve( (Curve *) ob->data );
+
+#if 0
+		/* copy_curve() sets disp.first null, so currently not need */
+		{
+			Curve *cu;
+			cu = (Curve *)tmpobj->data;
+			if( cu->disp.first )
+				MEM_freeN( cu->disp.first );
+			cu->disp.first = NULL;
+		}
 	
-	/* TODO: other types */
-	if(ob->type != OB_MESH) {
-		BKE_report(reports, RPT_ERROR, "Object should be of type MESH.");
-		return NULL;
-	}
+#endif
 
-	if (type == CREATE_MESH_PREVIEW) {
-		dm= mesh_create_derived_view(sce, ob, mask);
-	}
-	else {
-		dm= mesh_create_derived_render(sce, ob, mask);
-	}
+		/* get updated display list, and convert to a mesh */
+		makeDispListCurveTypes( sce, tmpobj, 0 );
+		nurbs_to_mesh( tmpobj );
+		
+		/* nurbs_to_mesh changes the type to a mesh, check it worked */
+		if (tmpobj->type != OB_MESH) {
+			free_libblock_us( &G.main->object, tmpobj );
+			BKE_report(reports, RPT_ERROR, "cant convert curve to mesh. Does the curve have any segments?");
+			return NULL;
+		}
+		tmpmesh = tmpobj->data;
+		free_libblock_us( &G.main->object, tmpobj );
+		break;
 
-	if(!dm) {
-		/* TODO: report */
-		return NULL;
-	}
+ 	case OB_MBALL:
+		/* metaballs don't have modifiers, so just convert to mesh */
+		ob = find_basis_mball( sce, ob );
+		tmpmesh = add_mesh("Mesh");
+		mball_to_mesh( &ob->disp, tmpmesh );
+ 		break;
 
-	me= add_mesh("tmp_render_mesh");
-	me->id.us--; /* we don't assign it to anything */
-	DM_to_mesh(dm, me);
-	dm->release(dm);
+ 	case OB_MESH:
+		/* copies object and modifiers (but not the data) */
+		if (cage) {
+			/* copies the data */
+			tmpmesh = copy_mesh( ob->data );
+		/* if not getting the original caged mesh, get final derived mesh */
+		} else {
+			/* Make a dummy mesh, saves copying */
+			DerivedMesh *dm;
+			/* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */
+			CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter,
+												   for example, needs CD_MASK_MDEFORMVERT */
+			
+			/* Write the display mesh into the dummy mesh */
+			if (render)
+				dm = mesh_create_derived_render( sce, ob, mask );
+			else
+				dm = mesh_create_derived_view( sce, ob, mask );
+			
+			tmpmesh = add_mesh( "Mesh" );
+			DM_to_mesh( dm, tmpmesh );
+			dm->release( dm );
+		}
+		
+		break;
+ 	default:
+		BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
+ 		return NULL;
+  	}
 
-	return me;
+	/* Copy materials to new mesh */
+	switch (ob->type) {
+	case OB_SURF:
+		tmpmesh->totcol = tmpcu->totcol;		
+		
+		/* free old material list (if it exists) and adjust user counts */
+		if( tmpcu->mat ) {
+			for( i = tmpcu->totcol; i-- > 0; ) {
+				/* are we an object material or data based? */
+				if (ob->colbits & 1<<i) 
+					tmpmesh->mat[i] = ob->mat[i];
+				else 
+					tmpmesh->mat[i] = tmpcu->mat[i];
+
+				if (tmpmesh->mat[i]) 
+					tmpmesh->mat[i]->id.us++;
+			}
+		}
+		break;
+
+#if 0
+	/* Crashes when assigning the new material, not sure why */
+	case OB_MBALL:
+		tmpmb = (MetaBall *)ob->data;
+		tmpmesh->totcol = tmpmb->totcol;
+		
+		/* free old material list (if it exists) and adjust user counts */
+		if( tmpmb->mat ) {
+			for( i = tmpmb->totcol; i-- > 0; ) {
+				tmpmesh->mat[i] = tmpmb->mat[i]; /* CRASH HERE ??? */
+				if (tmpmesh->mat[i]) {
+					tmpmb->mat[i]->id.us++;
+				}
+			}
+		}
+		break;
+#endif
+
+	case OB_MESH:
+		if (!cage) {
+			Mesh *origmesh= ob->data;
+			tmpmesh->flag= origmesh->flag;
+			tmpmesh->mat = MEM_dupallocN(origmesh->mat);
+			tmpmesh->totcol = origmesh->totcol;
+			tmpmesh->smoothresh= origmesh->smoothresh;
+			if( origmesh->mat ) {
+				for( i = origmesh->totcol; i-- > 0; ) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list