[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20633] branches/soc-2009-yukishiro/source /blender: collect selected faces and vertices.

Jingyuan Huang jingyuan.huang at gmail.com
Thu Jun 4 21:18:34 CEST 2009


Revision: 20633
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20633
Author:   yukishiro
Date:     2009-06-04 21:18:21 +0200 (Thu, 04 Jun 2009)

Log Message:
-----------
collect selected faces and vertices. need solver

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/brush.c
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/scene.c
    branches/soc-2009-yukishiro/source/blender/blenloader/intern/writefile.c
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_utils.c
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_buttons.c
    branches/soc-2009-yukishiro/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2009-yukishiro/source/blender/sh/SH_api.h

Added Paths:
-----------
    branches/soc-2009-yukishiro/source/blender/sh/intern/solve.c

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/brush.c	2009-06-04 18:38:10 UTC (rev 20632)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/brush.c	2009-06-04 19:18:21 UTC (rev 20633)
@@ -195,6 +195,8 @@
 		return &sce->toolsettings->wpaint->brush;
 	else if(G.f & G_TEXTUREPAINT)
 		return &sce->toolsettings->imapaint.brush;
+        else if(G.f & G_LIGHTPAINT)
+                return &sce->toolsettings->lpaint->brush;
 	return NULL;
 }
 

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/scene.c	2009-06-04 18:38:10 UTC (rev 20632)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/scene.c	2009-06-04 19:18:21 UTC (rev 20633)
@@ -128,6 +128,22 @@
 
 /* copy_scene moved to src/header_info.c... should be back */
 
+static void free_lightpaint_data(ListBase *paint_data)
+{
+        PaintStroke *ps, *next;
+
+        if (paint_data == NULL) return;
+        ps = paint_data->first;
+        while (ps) {
+                MEM_freeN(ps->v_index);
+                next = ps->next;
+                MEM_freeN(ps);
+                ps = next;
+        }
+        paint_data->first = NULL;
+        paint_data->last = NULL;
+}
+
 /* do not free scene itself */
 void free_scene(Scene *sce)
 {
@@ -177,8 +193,10 @@
 			MEM_freeN(sce->toolsettings->vpaint);
 		if(sce->toolsettings->wpaint)
 			MEM_freeN(sce->toolsettings->wpaint);
-		if(sce->toolsettings->lpaint)
+		if(sce->toolsettings->lpaint) {
+                        free_lightpaint_data(&sce->toolsettings->lpaint->lpaint_data);
 			MEM_freeN(sce->toolsettings->lpaint);
+                }
 		if(sce->toolsettings->sculpt) {
 			sculptsession_free(sce->toolsettings->sculpt);
 			MEM_freeN(sce->toolsettings->sculpt);

Modified: branches/soc-2009-yukishiro/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenloader/intern/writefile.c	2009-06-04 18:38:10 UTC (rev 20632)
+++ branches/soc-2009-yukishiro/source/blender/blenloader/intern/writefile.c	2009-06-04 19:18:21 UTC (rev 20633)
@@ -1587,11 +1587,11 @@
 		writestruct(wd, DATA, "Radio", 1, sce->radio);
 		writestruct(wd, DATA, "ToolSettings", 1, sce->toolsettings);
 		if(sce->toolsettings->vpaint)
-			writestruct(wd, DATA, "Vertex VPaint", 1, sce->toolsettings->vpaint);
+			writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->vpaint);
 		if(sce->toolsettings->wpaint)
-			writestruct(wd, DATA, "Weight VPaint", 1, sce->toolsettings->wpaint);
+			writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->wpaint);
 		if(sce->toolsettings->lpaint)
-			writestruct(wd, DATA, "Light VPaint", 1, sce->toolsettings->wpaint);
+			writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->wpaint);
 		if(sce->toolsettings->sculpt)
 			writestruct(wd, DATA, "Sculpt", 1, sce->toolsettings->sculpt);
 

Modified: branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h	2009-06-04 18:38:10 UTC (rev 20632)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h	2009-06-04 19:18:21 UTC (rev 20633)
@@ -65,6 +65,7 @@
 int imapaint_pick_face(struct ViewContext *vc, struct Mesh *me, int *mval, unsigned int *index);
 void imapaint_pick_uv(struct Scene *scene, struct Object *ob, struct Mesh *mesh, unsigned int faceindex, int *xy, float *uv);
 
+unsigned int rgba_to_mcol(float r, float g, float b, float a);
 void paint_sample_color(struct Scene *scene, struct ARegion *ar, int x, int y);
 int sample_backbuf_area(struct ViewContext *vc, int *indexar, int totface, int x, int y, float size);
 

Modified: branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-06-04 18:38:10 UTC (rev 20632)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-06-04 19:18:21 UTC (rev 20633)
@@ -85,7 +85,6 @@
 	short *do_update;
 } ShJob;
 
-extern unsigned int rgba_to_mcol(float r, float g, float b, float a);
 
 static void sh_freejob(void *sjv)
 {
@@ -144,7 +143,8 @@
 
 static unsigned int lpaint_get_current_col(VPaint *lp)
 {
-	return rgba_to_mcol(lp->brush->rgb[0], lp->brush->rgb[1], lp->brush->rgb[2], 1.0f);
+        // XXX: use vertex ABGR
+	return rgba_to_mcol(1.0f, lp->brush->rgb[2], lp->brush->rgb[1], lp->brush->rgb[0]);
 }
 
 /************************ light paint poll ************************/
@@ -284,10 +284,112 @@
 	ViewContext vc;
 	unsigned int paintcol;
 	int *indexar;
-	//float *vertexcosnos;
 	float vpimat[3][3];
 } PaintOperation;
 
+PaintStroke* create_stroke()
+{
+        PaintStroke *ps;
+        ps = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
+
+        ps->capacity = 100;
+        ps->size = 0;
+        ps->r = ps->g = ps->b = 0;
+        ps->v_index = MEM_callocN(sizeof(int) * ps->capacity, "StrokeIndex");
+        return ps;
+}
+
+static void double_capacity(PaintStroke *ps)
+{
+        int cap = ps->capacity * 2;
+        int *index = MEM_callocN(sizeof(int) * cap, "StrokeIndex");
+        
+        memcpy(index, ps->v_index, sizeof(int) * ps->size);
+        MEM_freeN(ps->v_index);
+        ps->v_index = index;
+        ps->capacity = cap;
+}
+
+static void add_face_vertices(PaintStroke *ps, MFace *mface)
+{
+        int i;
+        int bfv[4] = {1, 1, 1, 0};
+
+        if ((ps->capacity - ps->size) < 4) double_capacity(ps);
+
+        if (mface->v4) bfv[3] = 1;
+        for (i = 0; i < ps->size; i++) {
+                if (ps->v_index[i] == mface->v1) bfv[0] = 0;
+                if (ps->v_index[i] == mface->v2) bfv[1] = 0;
+                if (ps->v_index[i] == mface->v3) bfv[2] = 0;
+                if (mface->v4 && ps->v_index[i] == mface->v4) bfv[3] = 0;
+        }
+
+        if (bfv[0]) ps->v_index[ps->size++] = mface->v1;
+        if (bfv[1]) ps->v_index[ps->size++] = mface->v2;
+        if (bfv[2]) ps->v_index[ps->size++] = mface->v3;
+        if (bfv[3]) ps->v_index[ps->size++] = mface->v4;
+}
+
+static void compute_color(Scene *scene, const PaintStroke *ps)
+{
+        PaintStroke *cur_ps = ps;
+        Mesh *me; 
+        MShCoeffs *coeffs;
+        int totvert = 0, i, j, index;
+        int num_sh = 9; // (L+1) * (L+1)
+        float (*I)[3];
+        float *P;
+        float (*C)[3];
+
+        // get total number of verts
+        while (cur_ps) {
+                totvert += ps->size;
+                cur_ps = cur_ps->next;
+        }
+
+        // create arrays I, P, C
+        // TODO: find a solver that can solve r, g, b at the same time
+        P = MEM_callocN(sizeof(float) * totvert * num_sh, "P");
+        I = MEM_callocN(sizeof(float[3]) * totvert, "I");
+        C = MEM_callocN(sizeof(float[3]) * (num_sh > totvert ? num_sh : totvert), "C");
+
+        cur_ps = ps;
+        index = 0;
+        while (cur_ps) {
+                me = get_mesh(ps->ob);
+                coeffs= CustomData_get_layer(&me->vdata, CD_MSHCOEFFS);
+
+                // set P, I
+                for (i = 0; i < ps->size; i++) {
+                        for (j = 0; j < num_sh; j++) {
+                                P[index * num_sh + j] = coeffs[ps->v_index[i]].val[j];
+                        }
+                        I[index][0] = ps->r;
+                        I[index][1] = ps->g;
+                        I[index][2] = ps->b;
+                        index++;
+                }
+
+                cur_ps = cur_ps->next;
+        }
+
+        // call solver
+        SH_solve(P, I, totvert, num_sh, C);
+
+        // get light coeffs
+        LightEnv* env = get_scene_lightenv(scene);
+        for (i = 0; i < num_sh; i++) {
+                env->shcoeffs[i][0] = C[i][0];
+                env->shcoeffs[i][1] = C[i][1];
+                env->shcoeffs[i][2] = C[i][2];
+        } 
+
+        MEM_freeN(I);
+        MEM_freeN(P);
+        MEM_freeN(C);
+}
+
 static void lpaint_exit(bContext *C, wmOperator *op)
 {
 	PaintOperation *pop= op->customdata;
@@ -301,21 +403,29 @@
 {
 	ToolSettings *ts= CTX_data_tool_settings(C);
 	VPaint *lp= ts->lpaint;
-	
+	PaintOperation *pop= op->customdata;
+        PaintStroke *ps = (PaintStroke*)lp->lpaint_data.last;
+	ViewContext *vc= &pop->vc;
+        Scene *scene= vc->scene;
+	Object *ob= vc->obact;
+
 	switch(event->type) {
 		case LEFTMOUSE:
 			if(event->val==0) { /* release */
+                                PaintStroke *ps = (PaintStroke*)lp->lpaint_data.first;
+                                // call SH solver here
+                                compute_color(scene, ps);
+                                // signal for recompute
 				lpaint_exit(C, op);
+
+                                vc->rv3d->rflag |= RV3D_RECALCMCOL;
+			        ED_region_tag_redraw(vc->ar);
 				return OPERATOR_FINISHED;
 			}
 			/* pass on, first press gets painted too */
 			
 		case MOUSEMOVE: 
                 {
-			PaintOperation *pop= op->customdata;
-			ViewContext *vc= &pop->vc;
-                        Scene *scene= vc->scene;
-			Object *ob= vc->obact;
 			Mesh *me= ob->data;
 			float mat[4][4];
 			int *indexar= pop->indexar;
@@ -333,6 +443,7 @@
 			mval[1]= event->y - vc->ar->winrct.ymin;
 
                         totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], lp->brush->size);
+                        ps->ob = ob;
 			
 			for(index=0; index<totindex; index++) {
 				if(indexar[index] && indexar[index]<=me->totface) {
@@ -341,6 +452,9 @@
                                         unsigned char *shcol= DM_get_face_data_layer(dm, CD_SH_MCOL);
                                         unsigned int *mcol= (unsigned int*)shcol + 4*(indexar[index]-1);
 
+                                        add_face_vertices(ps, mface);
+
+                                        // TODO: blend it using alpha
                                         *mcol = pop->paintcol;
                                         *(mcol+1) = pop->paintcol;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list