[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30906] branches/soc-2010-nicolasbishop/ source/blender: == Paint ==

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 30 17:20:08 CEST 2010


Revision: 30906
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30906
Author:   nicholasbishop
Date:     2010-07-30 17:20:07 +0200 (Fri, 30 Jul 2010)

Log Message:
-----------
== Paint ==

* Refactored paint mask undo to support any customdata type
* Automatically make layer multires when adding vcols to a multires mesh in vpaint mode
* Fixed vcol multires toggle so that it updates the dm

TODO:
* Add paint undo for vcol layers

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
    branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h
    branches/soc-2010-nicolasbishop/source/blender/editors/mesh/mesh_data.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_undo.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h	2010-07-30 14:56:17 UTC (rev 30905)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h	2010-07-30 15:20:07 UTC (rev 30906)
@@ -235,8 +235,6 @@
 int CustomData_get_clone_layer(const struct CustomData *data, int type);
 int CustomData_get_stencil_layer(const struct CustomData *data, int type);
 
-char *CustomData_get_layer_name_at_offset(const struct CustomData *data, int type, int offset);
-
 /* copies the data from source to the data element at index in the first
  * layer of type
  * no effect if there is no layer of type
@@ -332,18 +330,23 @@
 
 /* if layer matching type and name exists, free and replace its griddata
    otherwise create the layer and set its griddata */
-void CustomData_multires_assign_data(struct CustomDataMultires *cdm, int type,
-				     char *name, float *data);
+void CustomData_multires_sync_layer(struct CustomDataMultires *cdm, int type,
+				    char *name);
 
-/* insert a multires layer of the specified type */
-void CustomData_multires_add_layer(struct CustomDataMultires *cdm, int type,
-				   char *name, float *data);
+/* insert a multires layer of the specified type and assign griddata */
+void CustomData_multires_add_layer_data(struct CustomDataMultires *cdm, int type,
+					char *name, float *griddata);
 
-/* remove the multires layer with matching source name
-   returns 1 if succesful, 0 otherwise */
-int CustomData_multires_remove_layer(struct CustomDataMultires *cdm, int type,
-				     char *name);
+/* insert a multires layer of the specified type int each
+   cdm in the array of length count */
+void CustomData_multires_add_layers(struct CustomDataMultires *cdm, int count,
+				    int type, char *name);
 
+/* remove the multires layer with matching source name from the cdm
+   array of length count, returns 1 if succesful, 0 otherwise */
+int CustomData_multires_remove_layers(struct CustomDataMultires *cdm, int count,
+				      int type, char *name);
+
 /* rename a layer matching type and old_name */
 void CustomData_multires_rename(struct CustomDataMultires *cdm, int type,
 				char *old_name, char *name);

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-07-30 14:56:17 UTC (rev 30905)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-07-30 15:20:07 UTC (rev 30906)
@@ -2524,24 +2524,32 @@
 		return cdm->layers[layer].griddata;
 }
 
-void CustomData_multires_assign_data(CustomDataMultires *cdm, int type,
-				     char *name, float *data)
+static float *customdata_multires_alloc_griddata(int type, int totelem)
 {
+	return MEM_callocN(sizeof(float) * totelem *
+			   CustomData_multires_type_totfloat(type),
+			   "CustomDataMultiresLayer.griddata");
+}
+
+void CustomData_multires_sync_layer(CustomDataMultires *cdm, int type,
+				    char *name)
+{
 	int layer;
 
 	layer = customdata_multires_find_named_layer_index(cdm, type, name);
 
 	if(layer == -1)
-		CustomData_multires_add_layer(cdm, type, name, data);
+		CustomData_multires_add_layer_data(cdm, type, name, NULL);
 	else {
 		if(cdm->layers[layer].griddata)
 			MEM_freeN(cdm->layers[layer].griddata);
-		cdm->layers[layer].griddata = data;
+		cdm->layers[layer].griddata =
+			customdata_multires_alloc_griddata(type, cdm->totelem);
 	}
 }
 
-void CustomData_multires_add_layer(CustomDataMultires *cdm, int type,
-				   char *name, float *data)
+void CustomData_multires_add_layer_data(CustomDataMultires *cdm, int type,
+					char *name, float *griddata)
 {
 	CustomDataMultiresLayer *old = cdm->layers;
 	int first, layer, i;
@@ -2559,11 +2567,17 @@
 	else
 		layer = first;
 
+	/* create griddata if none given */
+	if(!griddata) {
+		griddata =
+			customdata_multires_alloc_griddata(type, cdm->totelem);
+	}
+
 	for(i = 0; i <= cdm->totlayer; ++i) {
 		if(i < layer)
 			cdm->layers[i] = old[i];
 		else if(i == layer) {
-			cdm->layers[i].griddata = data;
+			cdm->layers[i].griddata = griddata;
 			cdm->layers[i].type = type;
 			BLI_strncpy(cdm->layers[i].name, name,
 				    sizeof(cdm->layers[i].name));
@@ -2576,9 +2590,21 @@
 	if(old) MEM_freeN(old);
 }
 
-int CustomData_multires_remove_layer(CustomDataMultires *cdm, int type,
-				      char *name)
+void CustomData_multires_add_layers(CustomDataMultires *cdm, int count,
+				   int type, char *name)
 {
+	int i;
+	
+	if(!cdm)
+		return;
+
+	for(i = 0; i < count; ++i, ++cdm)
+		CustomData_multires_add_layer_data(cdm, type, name, NULL);
+}
+
+static int CustomData_multires_layer_delete(CustomDataMultires *cdm, int type,
+					    char *name)
+{
 	CustomDataMultiresLayer *old = cdm->layers;
 	int layer, i;
 
@@ -2607,6 +2633,22 @@
 	return 1;
 }
 
+int CustomData_multires_remove_layers(CustomDataMultires *cdm, int count,
+				     int type, char *name)
+{
+	int i;
+	
+	if(!cdm)
+		return 0;
+
+	for(i = 0; i < count; ++i, ++cdm) {
+		if(!CustomData_multires_layer_delete(cdm, type, name))
+			return 0;
+	}
+
+	return 1;
+}
+
 void CustomData_multires_rename(CustomDataMultires *cdm, int type,
 				char *old_name, char *name)
 {

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-07-30 14:56:17 UTC (rev 30905)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-07-30 15:20:07 UTC (rev 30906)
@@ -298,20 +298,6 @@
 	}
 }
 
-static void multires_sync_customdata_layer(CustomDataMultires *cdm,
-					   char *name, int type, int totelem)
-{
-	float *griddata;
-	int totfloat;
-
-	totfloat = CustomData_multires_type_totfloat(type);
-
-	griddata = MEM_callocN(sizeof(float) * totfloat * totelem,
-			       "sync layer griddata");
-			
-	CustomData_multires_assign_data(cdm, type, name, griddata);
-}
-
 /* ensure all the layers needed by the gridkey have
    a matching multires layer
 
@@ -332,19 +318,19 @@
 		int nvert = (me->mface[i].v4)? 4: 3;
 		int totelem = multires_grid_tot[lvl]*nvert;
 
+		cd_grids[i].totelem = totelem;
+
 		for(j = 0; j < gridkey->color; ++j) {
-			multires_sync_customdata_layer(cd_grids+i,
-						       gridkey->color_names[j],
-						       CD_MCOL, totelem);
+			CustomData_multires_sync_layer(cd_grids+i,
+						       CD_MCOL,
+						       gridkey->color_names[j]);
 		}
 
 		for(j = 0; j < gridkey->mask; ++j) {
-			multires_sync_customdata_layer(cd_grids+i,
-						       gridkey->mask_names[j],
-						       CD_PAINTMASK, totelem);
+			CustomData_multires_sync_layer(cd_grids+i,
+						       CD_PAINTMASK,
+						       gridkey->mask_names[j]);
 		}
-
-		cd_grids[i].totelem = totelem;
 	}
 }
 

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h	2010-07-30 14:56:17 UTC (rev 30905)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h	2010-07-30 15:20:07 UTC (rev 30906)
@@ -30,8 +30,10 @@
 
 struct ARegion;
 struct bContext;
+struct MultiresModifierData;
 struct Object;
 struct RegionView3D;
+struct Scene;
 struct wmKeyConfig;
 struct wmWindowManager;
 
@@ -50,7 +52,15 @@
 int ED_undo_paint_step(struct bContext *C, int type, int step, const char *name);
 void ED_undo_paint_free(void);
 
+typedef struct PaintLayerUndoNode PaintLayerUndoNode;
+PaintLayerUndoNode *paint_layer_undo_push(int type, char *description);
+void paint_layer_undo_set_add(PaintLayerUndoNode *unode, char *name);
+void paint_layer_undo_set_remove(PaintLayerUndoNode *unode, char *name,
+				 struct CustomData *data, struct CustomData *fdata,
+				 int totvert, int totface);
+
 /* paint_util.c */
+struct MultiresModifierData *ED_paint_multires_active(struct Scene *scene, struct Object *ob);
 void paint_get_redraw_planes(float planes[4][4], struct ARegion *ar,
 			     struct RegionView3D *rv3d, struct Object *ob);
 

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/mesh/mesh_data.c	2010-07-30 14:56:17 UTC (rev 30905)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/mesh/mesh_data.c	2010-07-30 15:20:07 UTC (rev 30906)
@@ -47,6 +47,7 @@
 #include "BKE_library.h"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
+#include "BKE_multires.h"
 #include "BKE_report.h"
 
 #include "BLI_math.h"
@@ -61,6 +62,7 @@
 
 #include "ED_mesh.h"
 #include "ED_object.h"
+#include "ED_sculpt.h"
 #include "ED_uvedit.h"
 #include "ED_view3d.h"
 
@@ -413,6 +415,37 @@
 
 /*********************** vertex color operators ************************/
 
+static int vertex_color_multires_toggle(Object *ob)
+{
+	Mesh *me= ob->data;
+	CustomDataMultires *cdm;
+	CustomDataLayer *cdl;
+	int active;
+
+	/* so that dm is recalculated correctly after */
+	multires_force_update(ob);
+
+	active = CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
+	cdm = CustomData_get_layer(&me->fdata, CD_GRIDS);
+
+	if(active == -1)
+		return 1;
+
+	cdl = &me->fdata.layers[active];
+
+	if(cdm) {
+		if(cdl->flag & CD_FLAG_MULTIRES)
+			CustomData_multires_remove_layers(cdm, me->totface, CD_MCOL, cdl->name);
+		else
+			CustomData_multires_add_layers(cdm, me->totface, CD_MCOL, cdl->name);
+	}
+
+	/* note - if there's no griddata, it can still be synced up later */
+	cdl->flag ^= CD_FLAG_MULTIRES;
+
+	return 1;
+}
+
 static int vertex_color_add_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene= CTX_data_scene(C);
@@ -422,6 +455,10 @@
 	if(!ED_mesh_color_add(C, scene, ob, me))
 		return OPERATOR_CANCELLED;
 
+	if((ob->mode & OB_MODE_VERTEX_PAINT) &&
+	   ED_paint_multires_active(scene, ob))
+		vertex_color_multires_toggle(ob);
+
 	return OPERATOR_FINISHED;
 }
 
@@ -468,42 +505,10 @@
 
 static int vertex_color_multires_toggle_exec(bContext *C, wmOperator *op)
 {
-	Object *ob= CTX_data_active_object(C);
-	Mesh *me= ob->data;
-	CustomDataMultires *cdm;
-	CustomDataLayer *cdl;
-	int active, i;
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list