[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39710] branches/bmesh/blender/source/ blender: fix crash when exporting .obj and no materials; added rna access ' append' for material so import obj script doesn't fail

Howard Trickey howard.trickey at gmail.com
Fri Aug 26 16:36:30 CEST 2011


Revision: 39710
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39710
Author:   howardt
Date:     2011-08-26 14:36:30 +0000 (Fri, 26 Aug 2011)
Log Message:
-----------
fix crash when exporting .obj and no materials; added rna access 'append' for material so import obj script doesn't fail

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
    branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2011-08-26 11:35:33 UTC (rev 39709)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2011-08-26 14:36:30 UTC (rev 39710)
@@ -4621,47 +4621,49 @@
 	mloopuv = CustomData_get_layer(&dm->loopData, CD_MLOOPUV);
 	mloopcol = CustomData_get_layer(&dm->loopData, CD_MLOOPCOL);
 	
-	/*build material list*/
-	mp = mpoly;
-	for (i=0; i<dm->numPolyData; i++, (mtexpoly ? mtexpoly++ : NULL), mp++) {
-		int found = 0;
-		
-		j = 0;
-		while (!matlists[mp->mat_nr][j].end) {
-			Material *mat = ob->matbits[mp->mat_nr] ? ob->mat[mp->mat_nr] : me->mat[mp->mat_nr];
+	if (matlists) {
+		/*build material list*/
+		mp = mpoly;
+		for (i=0; i<dm->numPolyData; i++, (mtexpoly ? mtexpoly++ : NULL), mp++) {
+			int found = 0;
 			
-			if (matlists[mp->mat_nr][j].mat == mat) {
-				if (mtexpoly) { 
-					if (matlists[mp->mat_nr][j].poly.tpage == mtexpoly->tpage) {
+			j = 0;
+			while (!matlists[mp->mat_nr][j].end) {
+				Material *mat = ob->matbits[mp->mat_nr] ? ob->mat[mp->mat_nr] : me->mat[mp->mat_nr];
+				
+				if (matlists[mp->mat_nr][j].mat == mat) {
+					if (mtexpoly) { 
+						if (matlists[mp->mat_nr][j].poly.tpage == mtexpoly->tpage) {
+							found = 1;
+							break;
+						}
+					} else {
 						found = 1;
 						break;
 					}
-				} else {
-					found = 1;
-					break;
 				}
+				j++;
 			}
-			j++;
-		}
-		
-		if (!found) {
-			matlists[mp->mat_nr] = MEM_reallocN(matlists[mp->mat_nr], sizeof(**matlists)*(j+2));
 			
-			/*add sentinal*/
-			matlists[mp->mat_nr][j+1].end = 1;
-			matlists[mp->mat_nr][j].end = 0;
-			
-			if (ob->matbits && ob->matbits[mp->mat_nr]) {
-				matlists[mp->mat_nr][j].mat = ob->mat[mp->mat_nr];
-			} else {
-				matlists[mp->mat_nr][j].mat = me->mat[mp->mat_nr];
+			if (!found) {
+				matlists[mp->mat_nr] = MEM_reallocN(matlists[mp->mat_nr], sizeof(**matlists)*(j+2));
+				
+				/*add sentinal*/
+				matlists[mp->mat_nr][j+1].end = 1;
+				matlists[mp->mat_nr][j].end = 0;
+				
+				if (ob->matbits && ob->matbits[mp->mat_nr]) {
+					matlists[mp->mat_nr][j].mat = ob->mat[mp->mat_nr];
+				} else {
+					matlists[mp->mat_nr][j].mat = me->mat[mp->mat_nr];
+				}
+				
+				if (mtexpoly)
+					matlists[mp->mat_nr][j].poly = *mtexpoly;
 			}
 			
-			if (mtexpoly)
-				matlists[mp->mat_nr][j].poly = *mtexpoly;
+			face_mat_group[i] = j;
 		}
-		
-		face_mat_group[i] = j;
 	}
 
 	/*write material references*/
@@ -4695,18 +4697,21 @@
 			fprintf(file, "s off\n");
 		}
 		
-		if (matlists[mp->mat_nr][face_mat_group[i]].mat && matlists[mp->mat_nr][face_mat_group[i]].poly.tpage) {
-			sprintf(matname, "%s__%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name+2, 
-				matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name+2);
-		} else if (matlists[mp->mat_nr][face_mat_group[i]].mat) {
-			sprintf(matname, "%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name+2);
-		} else if (matlists[mp->mat_nr][face_mat_group[i]].poly.tpage != NULL) {
-			sprintf(matname, "texture_%s", matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name+2);
-		} else {
-			sprintf(matname, "__null_material_%d_%d", mp->mat_nr, face_mat_group[mp->mat_nr]);
+		if (matlists) {
+			if (matlists[mp->mat_nr][face_mat_group[i]].mat && matlists[mp->mat_nr][face_mat_group[i]].poly.tpage) {
+				sprintf(matname, "%s__%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name+2, 
+					matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name+2);
+			} else if (matlists[mp->mat_nr][face_mat_group[i]].mat) {
+				sprintf(matname, "%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name+2);
+			} else if (matlists[mp->mat_nr][face_mat_group[i]].poly.tpage != NULL) {
+				sprintf(matname, "texture_%s", matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name+2);
+			} else {
+				sprintf(matname, "__null_material_%d_%d", mp->mat_nr, face_mat_group[mp->mat_nr]);
+			}
+			
+			fprintf(file, "usemtl %s\n", matname);
 		}
 		
-		fprintf(file, "usemtl %s\n", matname);
 		fprintf(file, "f ");
 		
 		ml = mloop + mp->loopstart;

Modified: branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c	2011-08-26 11:35:33 UTC (rev 39709)
+++ branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c	2011-08-26 14:36:30 UTC (rev 39710)
@@ -1573,6 +1573,7 @@
 	RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
 	RNA_def_property_struct_type(prop, "Material");
 	RNA_def_property_ui_text(prop, "Materials", "");
+	RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
 }
 
 




More information about the Bf-blender-cvs mailing list