[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21249] branches/soc-2009-yukishiro/source /blender: sh coeffs should be recomputed when the object is transformed

Jingyuan Huang jingyuan.huang at gmail.com
Tue Jun 30 00:45:21 CEST 2009


Revision: 21249
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21249
Author:   yukishiro
Date:     2009-06-30 00:45:21 +0200 (Tue, 30 Jun 2009)

Log Message:
-----------
sh coeffs should be recomputed when the object is transformed

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/SConscript
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_draw.c
    branches/soc-2009-yukishiro/source/blender/makesdna/DNA_view3d_types.h
    branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Modified: branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c	2009-06-29 22:45:21 UTC (rev 21249)
@@ -406,7 +406,7 @@
 	BKE_reports_init(&reports, RPT_STORE);
 
 	if(ED_object_modifier_apply(&reports, scene, obv, mdv)) {
-		SH_computeMeshCoefficients(scene, ob);
+		SH_computeMeshCoefficients(scene, ob, 0); // no customdata mask, use mesh, not dm
 
 		WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
 		DAG_object_flush_update(scene, ob, OB_RECALC_DATA);

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_view3d/SConscript
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_view3d/SConscript	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_view3d/SConscript	2009-06-29 22:45:21 UTC (rev 21249)
@@ -7,7 +7,7 @@
 incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
 incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
 incs += ' ../../render/extern/include #/intern/guardedalloc'
-incs += ' ../../gpu ../../makesrna ../../blenfont'
+incs += ' ../../gpu ../../makesrna ../../blenfont ../../sh'
 
 if env['WITH_BF_GAMEENGINE']:
 	defs.append('GAMEBLENDER=1')

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c	2009-06-29 22:45:21 UTC (rev 21249)
@@ -109,6 +109,7 @@
 
 #include "WM_api.h"
 #include "BLF_api.h"
+#include "SH_api.h"
 
 #include "view3d_intern.h"	// own include
 
@@ -2370,9 +2371,28 @@
 		draw_wire = 2; /* draw wire after solid using zoffset and depth buffer adjusment */
 	}
 
-	if ((G.f & G_LIGHTPAINT) && (rv3d->rflag & RV3D_SHRESULT)) {
-		shcol= DM_get_face_data_layer(dm, CD_SH_MCOL);
-		if (shcol == NULL) shcol = add_sh_mcol_dm(scene, ob, dm);
+	if (G.f & G_LIGHTPAINT) {
+		if (!(scene->flag & SCE_SH_RESULT)) {
+			if (rv3d->rflag & RV3D_SHRESULT) {
+				scene->flag |= SCE_SH_RESULT;
+			}
+		}
+		if (rv3d->rflag & RV3D_SHRESULT) {
+			shcol= DM_get_face_data_layer(dm, CD_SH_MCOL);
+			if (shcol == NULL) shcol = add_sh_mcol_dm(scene, ob, dm);
+
+			if (base->flag & SELECT) {
+				if (rv3d->rflag & RV3D_RECALC_OBMCOL) {
+					calc_sh_color(scene, ob, dm, shcol);
+					rv3d->rflag &= ~RV3D_RECALC_OBMCOL;
+				}
+				else if (rv3d->rflag & RV3D_RECALC_SH) {
+					SH_computeMeshCoefficients(scene, ob, v3d->customdata_mask);
+					calc_sh_color(scene, ob, dm, shcol);
+					rv3d->rflag &= ~RV3D_RECALC_SH;
+				}
+			}
+		}
 	}
 	
 	totvert = dm->getNumVerts(dm);
@@ -2434,20 +2454,13 @@
 			draw_mesh_object_outline(v3d, ob, dm);
 
 		if (G.f & G_LIGHTPAINT) {
-			if (!(scene->flag & SCE_SH_RESULT)) {
-				if (rv3d->rflag & RV3D_SHRESULT) {
-					scene->flag |= SCE_SH_RESULT;
-				}
-			}
 			if (scene->flag & SCE_SH_RESULT) {
 				shcol= DM_get_face_data_layer(dm, CD_SH_MCOL);
-
-				if (rv3d->rflag & RV3D_RECALCMCOL) {
+				if (rv3d->rflag & RV3D_RECALC_MCOL) {
 					calc_sh_color(scene, ob, dm, shcol);
 				}
-				
+
 				glDisable(GL_LIGHTING);
-				
 				glColorMaterial(GL_FRONT,GL_DIFFUSE);
 				glEnable(GL_COLOR_MATERIAL); 
 				

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c	2009-06-29 22:45:21 UTC (rev 21249)
@@ -407,7 +407,6 @@
 			switch(wmn->data) {
 				case ND_BONE_ACTIVE:
 				case ND_BONE_SELECT:
-				case ND_TRANSFORM:
 				case ND_GEOM_SELECT:
 				case ND_GEOM_DATA:
 				case ND_DRAW:
@@ -417,6 +416,11 @@
 				case ND_PARTICLE:
 					ED_region_tag_redraw(ar);
 					break;
+				case ND_TRANSFORM:
+					rv3d = ar->regiondata;
+					rv3d->rflag |= RV3D_RECALC_SH;
+					ED_region_tag_redraw(ar);
+					break;
 			}
 		case NC_GROUP:
 			/* all group ops for now */
@@ -426,7 +430,7 @@
 			switch(wmn->data) {
 				case ND_SHADING_DRAW:
 					rv3d = ar->regiondata;
-					rv3d->rflag |= RV3D_RECALCMCOL;
+					rv3d->rflag |= RV3D_RECALC_OBMCOL;
 					ED_region_tag_redraw(ar);
 					break;
 			}
@@ -447,7 +451,7 @@
 			switch(wmn->data) {
 				case ND_SH_RESULT:
 					rv3d->rflag |= RV3D_SHRESULT;
-					rv3d->rflag |= RV3D_RECALCMCOL;
+					rv3d->rflag |= RV3D_RECALC_MCOL;
 					break;
 				case ND_SH_UPDATE:
 					rv3d->rflag &= ~RV3D_SHRESULT;

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_draw.c	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_draw.c	2009-06-29 22:45:21 UTC (rev 21249)
@@ -2092,8 +2092,8 @@
 		//}
 	}
 
-	if (rv3d->rflag & RV3D_RECALCMCOL)
-		rv3d->rflag &= ~RV3D_RECALCMCOL;
+	if (rv3d->rflag & RV3D_RECALC_MCOL)
+		rv3d->rflag &= ~RV3D_RECALC_MCOL;
 	
 #ifndef DISABLE_PYTHON
 	/* XXX here was scriptlink */

Modified: branches/soc-2009-yukishiro/source/blender/makesdna/DNA_view3d_types.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/makesdna/DNA_view3d_types.h	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/makesdna/DNA_view3d_types.h	2009-06-29 22:45:21 UTC (rev 21249)
@@ -206,7 +206,9 @@
 #define RV3D_FLYMODE		2
 #define RV3D_CLIPPING		4
 #define RV3D_SHRESULT		8
-#define RV3D_RECALCMCOL		16
+#define RV3D_RECALC_MCOL	16
+#define RV3D_RECALC_OBMCOL	32
+#define RV3D_RECALC_SH		64
 
 /* RegionView3d->viewlock */
 #define RV3D_LOCKED		1

Modified: branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-06-29 22:45:21 UTC (rev 21249)
@@ -39,7 +39,7 @@
 
 void SH_computeSceneCoefficients(struct Scene *scene, unsigned int customdata_mask, 
 				 short compute_shadow, short recompute);
-void SH_computeMeshCoefficients(struct Object *ob, int compute_shadow);
+void SH_computeMeshCoefficients(struct Object *ob, int compute_shadow, unsigned int customdata_mask);
 void SH_computeLightCoefficients(struct LightEnv *env);
 
 void SH_rotateLightEnv(struct LightEnv *env, float quat[4]);

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-06-29 22:16:48 UTC (rev 21248)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-06-29 22:45:21 UTC (rev 21249)
@@ -566,7 +566,7 @@
 
 	Isect isec;
         int i, k, m;
-        float N, *y_val;
+        float no[3], N, *y_val;
         int num_verts= 0;
 	int num_sh= (env->degree + 1) * (env->degree + 1);
         float weight= 4.0f/(float)NUM_SAMPLES;
@@ -598,10 +598,13 @@
 
                 for (i = 0; i < num_verts; i++) {
                         for (k = 0; k < NUM_SAMPLES; k++) {
-                                N = (samples[k][0] * verts[i].no[0] +
-                                     samples[k][1] * verts[i].no[1] +
-                                     samples[k][2] * verts[i].no[2]) / 32767.0;
+				no[0] = verts[i].no[0] / 32767.0;
+				no[1] = verts[i].no[1] / 32767.0;
+				no[2] = verts[i].no[2] / 32767.0;
+				Mat4MulVecfl(ob->obmat, no); // XXX
 
+                                N = samples[k][0] * no[0] + samples[k][1] * no[1] + samples[k][2] * no[2];
+
                                 if (N > 0) {
 					if (compute_shadow) {
 						memset(&isec, 0, sizeof(isec));
@@ -633,32 +636,45 @@
         }
 }
 
-void SH_computeMeshCoefficients(Scene *scene, Object *ob)
+void SH_computeMeshCoefficients(Scene *scene, Object *ob, unsigned int customdata_mask)
 {
         Mesh *me= NULL;
+        DerivedMesh *dm= NULL;
         MShCoeffs *coeffs= NULL;
+        int num_verts= 0;
         MVert* verts= NULL;
 	LightEnv* env=scene->lightenv;
 
         int i, k, m;
-        float N, *y_val;
+        float no[3], N, *y_val;
 	int num_sh= (env->degree + 1) * (env->degree + 1);
         float weight= 4.0f/(float)NUM_SAMPLES;
 
 	me = get_mesh(ob);
 	if (me == NULL) return;
+
+	if (customdata_mask != 0) {
+		dm = mesh_get_derived_final(scene, ob, customdata_mask);
+		num_verts = dm->getNumVerts(dm);
+		verts = dm->getVertArray(dm);
+	} else {
+		num_verts = me->totvert;
+		verts = me->mvert;
+	}
 	
 	coeffs= CustomData_get_layer(&me->vdata, CD_MSHCOEFFS);
 	if (coeffs == NULL) {
-		coeffs= MEM_callocN(sizeof(MShCoeffs) * me->totvert, "sh coeffs");
-		CustomData_add_layer(&me->vdata, CD_MSHCOEFFS, CD_ASSIGN, coeffs, me->totvert);
+		coeffs = CustomData_add_layer(&me->vdata, CD_MSHCOEFFS, CD_CALLOC, NULL, me->totvert);
 	}
 	
-	for (i = 0; i < me->totvert; i++) {
+	for (i = 0; i < num_verts; i++) {
 	        for (k = 0; k < NUM_SAMPLES; k++) {
-	                N = (samples[k][0] * me->mvert[i].no[0] +
-	                     samples[k][1] * me->mvert[i].no[1] +
-	                     samples[k][2] * me->mvert[i].no[2]) / 32767.0;
+			no[0] = verts[i].no[0] / 32767.0;
+			no[1] = verts[i].no[1] / 32767.0;
+			no[2] = verts[i].no[2] / 32767.0;
+			Mat4MulVecfl(ob->obmat, no); // XXX
+
+	                N = samples[k][0] * no[0] + samples[k][1] * no[1] + samples[k][2] * no[2];
 	
 	                if (N > 0) {
 	                        y_val = *(samples_Y[k]);





More information about the Bf-blender-cvs mailing list