[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21553] branches/blender2.5/blender: 2.5

Brecht Van Lommel brecht at blender.org
Mon Jul 13 02:40:20 CEST 2009


Revision: 21553
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21553
Author:   blendix
Date:     2009-07-13 02:40:20 +0200 (Mon, 13 Jul 2009)

Log Message:
-----------
2.5

* Objects now support up to 32767 material slots. It's easy to
  increase this further, but I prefer not to increase the memory
  usage of mesh faces, it seems unlikely that someone would
  create 32767 distinct materials?
* Forward compatibility: the only thing you can potentially lose
  reading a 2.5 file in 2.4 is object linking (instead of default
  data), though usually that will go fine too. Reading files with
  > 32 material slots in 2.4 can start giving issues.

* The ob->colbits variable is deprecated by the array ob->matbits
  but I didn't remove the ob->colbits updates in very few places
  it is set.
* I hope I changed all the relevant things, various places just
  hardcoded the number 16 instead of using the MAXMAT define.

* Join Objects operator back. This is using the version from the
  animsys2 branch coded by Joshua, which means it now supports
  joining of shape keys.

* Fix for crash reading file saved during render.

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_material.py
    branches/blender2.5/blender/source/blender/blenkernel/intern/exotic.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/material.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/object.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c
    branches/blender2.5/blender/source/blender/blenlib/BLI_editVert.h
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
    branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
    branches/blender2.5/blender/source/blender/editors/curve/editcurve.c
    branches/blender2.5/blender/source/blender/editors/include/ED_armature.h
    branches/blender2.5/blender/source/blender/editors/include/ED_curve.h
    branches/blender2.5/blender/source/blender/editors/include/ED_mesh.h
    branches/blender2.5/blender/source/blender/editors/include/ED_transform.h
    branches/blender2.5/blender/source/blender/editors/mesh/editmesh.c
    branches/blender2.5/blender/source/blender/editors/mesh/meshtools.c
    branches/blender2.5/blender/source/blender/editors/object/object_edit.c
    branches/blender2.5/blender/source/blender/editors/object/object_intern.h
    branches/blender2.5/blender/source/blender/editors/object/object_ops.c
    branches/blender2.5/blender/source/blender/editors/space_image/image_ops.c
    branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/drawobject.c
    branches/blender2.5/blender/source/blender/gpu/GPU_draw.h
    branches/blender2.5/blender/source/blender/gpu/intern/gpu_draw.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_material_types.h
    branches/blender2.5/blender/source/blender/makesdna/DNA_meshdata_types.h
    branches/blender2.5/blender/source/blender/makesdna/DNA_object_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_curve.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
    branches/blender2.5/blender/source/blender/render/intern/source/convertblender.c

Modified: branches/blender2.5/blender/release/ui/buttons_material.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_material.py	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/release/ui/buttons_material.py	2009-07-13 00:40:20 UTC (rev 21553)
@@ -47,11 +47,11 @@
 
 		if ob and slot:
 			split.template_ID(slot, "material", new="MATERIAL_OT_new")
-			#split.itemR(ob, "active_material_index", text="Active")
+			row = split.row()
+			row.itemR(slot, "link", expand=True)
 		elif mat:
 			split.template_ID(space, "pin_id")
 			split.itemS()
-
 	
 class MATERIAL_PT_material(MaterialButtonsPanel):
 	__idname__= "MATERIAL_PT_material"

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/exotic.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/exotic.c	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/exotic.c	2009-07-13 00:40:20 UTC (rev 21553)
@@ -1415,11 +1415,6 @@
 		return;
 	}
 	
-	if(totcol>16) {
-		//XXX error("Found more than 16 different colors");
-		totcol= 16;
-	}
-
 	vec[0]= (min[0]+max[0])/2;
 	vec[1]= (min[1]+max[1])/2;
 	vec[2]= (min[2]+max[2])/2;
@@ -1433,6 +1428,7 @@
 	/* colors */
 	if(totcol) {
 		ob->mat= MEM_callocN(sizeof(void *)*totcol, "ob->mat");
+		ob->matbits= MEM_callocN(sizeof(char)*totcol, "ob->matbits");
 		me->mat= MEM_callocN(sizeof(void *)*totcol, "me->mat");
 		me->totcol= totcol;
 		ob->totcol= (unsigned char) me->totcol;
@@ -1482,7 +1478,7 @@
 	dl= dlfirst;
 	while(dl) {
 		
-		colnr= (dl->col>15 ? 15: dl->col);
+		colnr= dl->col;
 		if(colnr) colnr--;
 		
 		if(dl->type==DL_SURF) {
@@ -2804,8 +2800,11 @@
 	
 	if (!me) return;
 	
-	if(ob) ob->mat= MEM_callocN(sizeof(void *)*1, "ob->mat");
-	if(ob) ob->actcol= 1;
+	if(ob) {
+		ob->mat= MEM_callocN(sizeof(void *)*1, "ob->mat");
+		ob->matbits= MEM_callocN(sizeof(char)*1, "ob->matbits");
+		ob->actcol= 1;
+	}
 
 	me->totcol= 1;
 	me->mat= MEM_callocN(sizeof(void *)*1, "me->mat");
@@ -4053,7 +4052,6 @@
 						ob->type= OB_MESH;
 	
 						ob->dt= OB_SHADED;
-						if(U.flag & USER_MAT_ON_OB) ob->colbits= -1;
 
 						ob->trackflag= OB_POSY;
 						ob->upflag= OB_POSZ;
@@ -4072,9 +4070,10 @@
 						VECCOPY(ob->rot, obrot);
 						
 						ob->mat= MEM_callocN(sizeof(void *)*1, "ob->mat");
+						ob->matbits= MEM_callocN(sizeof(char)*1, "ob->matbits");
 						ob->totcol= (unsigned char) ((Mesh*)ob->data)->totcol;
 						ob->actcol= 1;
-						
+
 						/* note: materials are either linked to mesh or object, if both then 
 							you have to increase user counts. below line is not needed.
 							I leave it commented out here as warning (ton) */

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/material.c	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/material.c	2009-07-13 00:40:20 UTC (rev 21553)
@@ -43,6 +43,7 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_texture_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"		
@@ -445,7 +446,7 @@
 	if(act>ob->totcol) act= ob->totcol;
 	else if(act<=0) act= 1;
 
-	if( BTST(ob->colbits, act-1) ) {	/* in object */
+	if(ob->matbits[act-1]) {	/* in object */
 		ma= ob->mat[act-1];
 	}
 	else {								/* in data */
@@ -473,7 +474,7 @@
 	if(ob->totcol==0) return ob->data;
 	if(act==0) act= 1;
 
-	if( BTST(ob->colbits, act-1) ) return (ID *)ob;
+	if(ob->matbits[act-1]) return (ID *)ob;
 	else return ob->data;
 }
 
@@ -498,6 +499,7 @@
 	Curve *cu;
 	MetaBall *mb;
 	Material **newmatar;
+	char *newmatbits;
 	int totcol=0;
 
 	if(id==0) return;
@@ -524,16 +526,22 @@
 			if(totcol==0) {
 				if(ob->totcol) {
 					MEM_freeN(ob->mat);
-					ob->mat= 0;
+					MEM_freeN(ob->matbits);
+					ob->mat= NULL;
+					ob->matbits= NULL;
 				}
 			}
 			else if(ob->totcol<totcol) {
 				newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar");
+				newmatbits= MEM_callocN(sizeof(char)*totcol, "newmatbits");
 				if(ob->totcol) {
 					memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol);
+					memcpy(newmatbits, ob->matbits, sizeof(char)*ob->totcol);
 					MEM_freeN(ob->mat);
+					MEM_freeN(ob->matbits);
 				}
 				ob->mat= newmatar;
+				ob->matbits= newmatbits;
 			}
 			ob->totcol= totcol;
 			if(ob->totcol && ob->actcol==0) ob->actcol= 1;
@@ -547,6 +555,7 @@
 void assign_material(Object *ob, Material *ma, int act)
 {
 	Material *mao, **matar, ***matarar;
+	char *matbits;
 	short *totcolp;
 
 	if(act>MAXMAT) return;
@@ -559,29 +568,41 @@
 	
 	if(totcolp==0 || matarar==0) return;
 	
-	if( act > *totcolp) {
+	if(act > *totcolp) {
 		matar= MEM_callocN(sizeof(void *)*act, "matarray1");
-		if( *totcolp) {
-			memcpy(matar, *matarar, sizeof(void *)*( *totcolp ));
+
+		if(*totcolp) {
+			memcpy(matar, *matarar, sizeof(void *)*(*totcolp));
 			MEM_freeN(*matarar);
 		}
+
 		*matarar= matar;
 		*totcolp= act;
 	}
 	
 	if(act > ob->totcol) {
 		matar= MEM_callocN(sizeof(void *)*act, "matarray2");
+		matbits= MEM_callocN(sizeof(char)*act, "matbits1");
 		if( ob->totcol) {
 			memcpy(matar, ob->mat, sizeof(void *)*( ob->totcol ));
+			memcpy(matbits, ob->matbits, sizeof(char)*(*totcolp));
 			MEM_freeN(ob->mat);
+			MEM_freeN(ob->matbits);
 		}
 		ob->mat= matar;
+		ob->matbits= matbits;
 		ob->totcol= act;
+
+		/* copy object/mesh linking, or assign based on userpref */
+		if(ob->actcol)
+			ob->matbits[act-1]= ob->matbits[ob->actcol-1];
+		else
+			ob->matbits[act-1]= (U.flag & USER_MAT_ON_OB)? 1: 0;
 	}
 	
 	/* do it */
 
-	if( BTST(ob->colbits, act-1) ) {	/* in object */
+	if(ob->matbits[act-1]) {	/* in object */
 		mao= ob->mat[act-1];
 		if(mao) mao->id.us--;
 		ob->mat[act-1]= ma;
@@ -591,6 +612,7 @@
 		if(mao) mao->id.us--;
 		(*matarar)[act-1]= ma;
 	}
+
 	id_us_plus((ID *)ma);
 	test_object_materials(ob->data);
 }
@@ -630,12 +652,6 @@
 	
 	ma->id.us= 0; /* eeh... */
 	
-	if(ob->actcol) {
-		if( BTST(ob->colbits, ob->actcol-1) ) {
-			ob->colbits= BSET(ob->colbits, ob->totcol);
-		}
-	}
-	
 	assign_material(ob, ma, ob->totcol+1);
 	ob->actcol= ob->totcol;
 }
@@ -880,9 +896,8 @@
 		if(mao) mao->id.us--;
 	}
 	
-	for(a=ob->actcol; a<ob->totcol; a++) {
+	for(a=ob->actcol; a<ob->totcol; a++)
 		(*matarar)[a-1]= (*matarar)[a];
-	}
 	(*totcolp)--;
 	
 	if(*totcolp==0) {
@@ -900,13 +915,18 @@
 			mao= obt->mat[actcol-1];
 			if(mao) mao->id.us--;
 		
-			for(a=actcol; a<obt->totcol; a++) obt->mat[a-1]= obt->mat[a];
+			for(a=actcol; a<obt->totcol; a++) {
+				obt->mat[a-1]= obt->mat[a];
+				obt->matbits[a-1]= obt->matbits[a];
+			}
 			obt->totcol--;
 			if(obt->actcol > obt->totcol) obt->actcol= obt->totcol;
 			
 			if(obt->totcol==0) {
 				MEM_freeN(obt->mat);
+				MEM_freeN(obt->matbits);
 				obt->mat= 0;
+				obt->matbits= NULL;
 			}
 		}
 		obt= obt->id.next;

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/object.c	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/object.c	2009-07-13 00:40:20 UTC (rev 21553)
@@ -243,7 +243,9 @@
 		if(ob->mat[a]) ob->mat[a]->id.us--;
 	}
 	if(ob->mat) MEM_freeN(ob->mat);
+	if(ob->matbits) MEM_freeN(ob->matbits);
 	ob->mat= 0;
+	ob->matbits= 0;
 	if(ob->bb) MEM_freeN(ob->bb); 
 	ob->bb= 0;
 	if(ob->path) free_path(ob->path); 
@@ -942,7 +944,6 @@
 	Mat4One(ob->parentinv);
 	Mat4One(ob->obmat);
 	ob->dt= OB_SHADED;
-	if(U.flag & USER_MAT_ON_OB) ob->colbits= -1;
 	ob->empty_drawtype= OB_ARROWS;
 	ob->empty_drawsize= 1.0;
 
@@ -1170,6 +1171,7 @@
 	
 	if(ob->totcol) {
 		obn->mat= MEM_dupallocN(ob->mat);
+		obn->matbits= MEM_dupallocN(ob->matbits);
 	}
 	
 	if(ob->bb) obn->bb= MEM_dupallocN(ob->bb);
@@ -1397,7 +1399,9 @@
 	/* copy material and index information */
 	ob->actcol= ob->totcol= 0;
 	if(ob->mat) MEM_freeN(ob->mat);
+	if(ob->matbits) MEM_freeN(ob->matbits);
 	ob->mat = NULL;
+	ob->matbits= NULL;
 	if ((target->totcol) && (target->mat) && ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { //XXX OB_SUPPORT_MATERIAL
 		int i;
 		ob->colbits = target->colbits;
@@ -1406,6 +1410,7 @@
 		ob->totcol= target->totcol;
 		
 		ob->mat = MEM_dupallocN(target->mat);
+		ob->matbits = MEM_dupallocN(target->matbits);
 		for(i=0; i<target->totcol; i++) {
 			/* dont need to run test_object_materials since we know this object is new and not used elsewhere */
 			id_us_plus((ID *)ob->mat[i]); 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c	2009-07-13 00:40:20 UTC (rev 21553)
@@ -784,7 +784,7 @@
 		if(act>ob->totcol) act= ob->totcol;
 		else if(act==0) act= 1;
 		
-		if( BTST(ob->colbits, act-1) ) {	/* in object */
+		if(ob->matbits[act-1]) {	/* in object */
 			ma= ob->mat[act-1];
 		}
 		else {								/* in data */

Modified: branches/blender2.5/blender/source/blender/blenlib/BLI_editVert.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/BLI_editVert.h	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/source/blender/blenlib/BLI_editVert.h	2009-07-13 00:40:20 UTC (rev 21553)
@@ -125,10 +125,11 @@
 		float			fp;
 	} tmp;
 	float n[3], cent[3];
-	unsigned char mat_nr, flag;
+	unsigned char flag;
 	unsigned char f, f1, h;
 	unsigned char fast;			/* only 0 or 1, for editmesh_fastmalloc */
 	unsigned char fgonf;		/* flag for fgon options */
+	short mat_nr;
 	void *data;		/* custom face data */
 } EditFace;
 

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-07-12 23:38:47 UTC (rev 21552)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-07-13 00:40:20 UTC (rev 21553)
@@ -3732,6 +3732,7 @@
 
 	ob->mat= newdataadr(fd, ob->mat);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list