[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21001] branches/soc-2009-yukishiro: 1.

Jingyuan Huang jingyuan.huang at gmail.com
Fri Jun 19 07:22:58 CEST 2009


Revision: 21001
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21001
Author:   yukishiro
Date:     2009-06-19 07:22:58 +0200 (Fri, 19 Jun 2009)

Log Message:
-----------
1. add light rotation. However the math isn't quite right now, so rotation doesn't work as expected.
2. modify image probe loading part. Now it references an existing image in the library

Modified Paths:
--------------
    branches/soc-2009-yukishiro/release/ui/buttons_lightenv.py
    branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.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_ops.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_edit.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_ops.c
    branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h
    branches/soc-2009-yukishiro/source/blender/makesrna/intern/rna_lightenv.c
    branches/soc-2009-yukishiro/source/blender/render/intern/source/rendercore.c
    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/release/ui/buttons_lightenv.py
===================================================================
--- branches/soc-2009-yukishiro/release/ui/buttons_lightenv.py	2009-06-19 04:58:40 UTC (rev 21000)
+++ branches/soc-2009-yukishiro/release/ui/buttons_lightenv.py	2009-06-19 05:22:58 UTC (rev 21001)
@@ -61,7 +61,8 @@
                 
                 lightenv = context.lightenv
                 scene = context.scene
-                split.template_ID(context, lightenv, "probe_image", new="IMAGE_OT_open")
+                #split.template_ID(context, lightenv, "probe_image", new="IMAGE_OT_open")
+		layout.itemR(lightenv, "probe_image")
 
 bpy.types.register(LIGHT_PT_compute)
 bpy.types.register(LIGHT_PT_preview)

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h	2009-06-19 04:58:40 UTC (rev 21000)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h	2009-06-19 05:22:58 UTC (rev 21001)
@@ -43,8 +43,10 @@
 void free_lightenv(struct LightEnv *env); 
 void add_lightenv(struct Scene *scene, char *name);
 
+void update_light_func(struct LightEnv *env);
+
 void load_probe_image(struct LightEnv *env, char *image_name);
-void set_probe_image(struct LightEnv *env, struct Image *image);
+void update_probe_image(struct LightEnv *env);
 
 #ifdef __cplusplus
 }

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-06-19 04:58:40 UTC (rev 21000)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-06-19 05:22:58 UTC (rev 21001)
@@ -72,26 +72,33 @@
         val[2] = fval[2];
 }
 
+void update_light_func(LightEnv *env)
+{
+	if (env->type == LE_PROBE) {
+		env->light_func = probe_value;
+	} else {
+        	env->light_func = def_synthetic;
+	}
+}
+
 void load_probe_image(LightEnv *env, const char *image_name)
 {
         env->probe_image = BKE_add_image_file(image_name, 0);
         env->type = LE_PROBE;
         env->light_func = probe_value;
-        SH_ComputeLightCoefficients(env);
+        SH_computeLightCoefficients(env);
 }
 
-void set_probe_image(LightEnv *env, Image *image)
+void update_probe_image(LightEnv *env)
 {
-        env->probe_image = image;
-        env->type = LE_PROBE;
-        env->light_func = probe_value;
-        SH_ComputeLightCoefficients(env);
+	env->light_func = probe_value;
+        SH_computeLightCoefficients(env);
 }
 
 static void save_probe_image(LightEnv *env, char *image_name, int w, int h)
 {
         ImBuf * ibuf= IMB_allocImBuf(w, h, 32, IB_rectfloat, 0);
-        SH_ReconstructLightProbe(env, ibuf);
+        SH_reconstructLightProbe(env, ibuf);
         IMB_saveiff(ibuf, image_name, 0);
         IMB_freeImBuf(ibuf);
 }
@@ -111,7 +118,7 @@
         env->light_func = def_synthetic;
 	env->degree = 2;
 	env->num_samples = 10;
-        SH_ComputeLightCoefficients(env);
+        SH_computeLightCoefficients(env);
 
         scene->lightenv = env;
 }

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-19 04:58:40 UTC (rev 21000)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h	2009-06-19 05:22:58 UTC (rev 21001)
@@ -60,6 +60,7 @@
 void PAINT_OT_light_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_light_paint(struct wmOperatorType *ot);
 void PAINT_OT_light_paint_radial_control(struct wmOperatorType *ot);
+void PAINT_OT_light_paint_rotate(struct wmOperatorType *ot);
 void PAINT_OT_light_paint_recompute(struct wmOperatorType *ot);
 
 /* paint_utils.c */

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-19 04:58:40 UTC (rev 21000)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-06-19 05:22:58 UTC (rev 21001)
@@ -56,6 +56,7 @@
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_utildefines.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -80,6 +81,7 @@
 #include "paint_intern.h"
 
 extern CustomDataMask get_viewedit_datamask(bScreen *screen); //defined in view3d_draw.c
+extern void calctrackballvec(rcti *rect, int mx, int my, float *vec); //defined in view3d_edit.c
 
 /******************* computation job ****************/
 typedef struct ShJob {
@@ -108,12 +110,12 @@
         if (sj->scene->lightenv == NULL) 
 		add_lightenv(sj->scene, "LightEnv");
 
-        SH_ComputeSceneCoefficients(sj->scene, sj->mask, sj->recompute);
+        SH_computeSceneCoefficients(sj->scene, sj->mask, sj->recompute);
 }
 
 
 // TODO: problem with using a job for the scene is that info header would display a render button....
-static void light_paint_compute(bContext *C, short recompute)
+static int light_paint_compute(bContext *C, short recompute)
 {
         Scene *scene= CTX_data_scene(C);
         wmJob *job;
@@ -146,6 +148,8 @@
 
 	/* add modal handler for ESC */
 	//WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+
+	return OPERATOR_FINISHED;
 }
 
 /*************************** undo and redo *********************************/
@@ -158,7 +162,7 @@
 static ListBase strokes;
 static ListBase undo_coeffs;
 static ListBase redo_coeffs;
-static init_coeffs[25][3];
+static float init_coeffs[25][3];
 
 static void undo_lightpaint_push(Scene *scene)
 {
@@ -194,7 +198,6 @@
 void undo_lightpaint_step(bContext *C, int step)
 {
         VPaint *lp = CTX_data_tool_settings(C)->lpaint;
-        RegionView3D *rv3d = CTX_wm_region_view3d(C);
         Scene *scene = CTX_data_scene(C);
         LightEnv *env = scene->lightenv;
         PaintStroke *ps;
@@ -247,8 +250,7 @@
                 }
         }
 
-        rv3d->rflag |= RV3D_RECALCMCOL;
-        ED_region_tag_redraw(CTX_wm_region(C));
+	WM_event_add_notifier(C, NC_LIGHTENV|ND_SH_RESULT, NULL);
 }
 
 
@@ -259,6 +261,19 @@
 }
 
 /************************ light paint poll ************************/
+static int light_paint_rotate_poll(bContext *C)
+{
+	if(G.f & G_LIGHTPAINT) {
+		ScrArea *sa= CTX_wm_area(C);
+		if(sa->spacetype==SPACE_VIEW3D) {
+			ARegion *ar= CTX_wm_region(C);
+			if(ar->regiontype==RGN_TYPE_WINDOW)
+				return 1;
+		}
+	}
+	return 0;
+}
+
 static int light_paint_poll(bContext *C)
 {
 	if(G.f & G_LIGHTPAINT) {
@@ -466,12 +481,15 @@
         LightEnv *env;
         Mesh *me; 
         MShCoeffs *coeffs;
-        int num_sh = 9, totvert = 0; // (L+1) * (L+1)
+        int num_sh, totvert = 0; 
         int iter = 1, i, j, k, index;
         float *I[3];
         float *P;
         float *C[3];
 
+        env = scene->lightenv;
+	num_sh = (env->degree + 1) * (env->degree + 1);
+
         // get total number of verts
         while (cur_ps) {
                 totvert += cur_ps->size;
@@ -519,7 +537,6 @@
         SH_solve(P, I, totvert, num_sh, C);
 
         // get light coeffs
-        env = scene->lightenv;
         for (i = 0; i < num_sh; i++) {
                 env->shcoeffs[i][0] = C[0][i];
                 env->shcoeffs[i][1] = C[1][i];
@@ -669,9 +686,88 @@
 }
 
 
+/************************ light paint rotation ************************/
+typedef struct RotateOperation {
+	ARegion *ar;
+	float trackvec[3];
+	float quat[4];
+	int origx, origy, oldx, oldy;
+	int origkey;
+} RotateOperation;
+
+#define TRACKBALLSIZE (1.1)
+
+static void light_paint_rotate_exit(bContext *C, wmOperator *op)
+{
+	RotateOperation *rop = op->customdata;
+	MEM_freeN(rop);
+	op->customdata = NULL;
+}
+
+static int light_paint_rotate_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+	RotateOperation *rop= op->customdata;
+        LightEnv *env= CTX_data_scene(C)->lightenv;
+
+	switch(event->type) {
+		case MOUSEMOVE: // use trackball
+		{
+			float phi, si, q1[4], dvec[3], newvec[3];
+			calctrackballvec(&rop->ar->winrct, event->x, event->y, newvec);
+			VecSubf(dvec, newvec, rop->trackvec);
+
+			si= sqrt(dvec[0]*dvec[0]+ dvec[1]*dvec[1]+ dvec[2]*dvec[2]);
+			si/= (2.0*TRACKBALLSIZE);
+			
+			Crossf(q1+1, rop->trackvec, newvec);
+			Normalize(q1+1);
+			
+			while (si > 1.0) si -= 2.0;
+			phi = si * M_PI / 10.0;
+
+			si= sin(phi);
+			q1[0]= cos(phi);
+			q1[1]*= si;
+			q1[2]*= si;
+			q1[3]*= si;
+			SH_rotateLightEnv(env, q1);
+
+			QuatMul(rop->quat, q1, rop->quat);
+
+			WM_event_add_notifier(C, NC_LIGHTENV|ND_SH_RESULT, NULL);
+		}
+		default:
+			if(event->type==rop->origkey && event->val==0) { /* release */
+				light_paint_rotate_exit(C, op);
+				return OPERATOR_FINISHED;
+			}
+	}
+	return OPERATOR_RUNNING_MODAL;
+}
+
+static int light_paint_rotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	RotateOperation *rop;
+
+	op->customdata = rop = MEM_callocN(sizeof(RotateOperation), "LightROP");
+	rop->ar= CTX_wm_region(C);
+	rop->origx= rop->oldx= event->x;
+	rop->origy= rop->oldy= event->y;
+	rop->origkey= event->type;
+	QuatOne(rop->quat);
+
+	calctrackballvec(&rop->ar->winrct, event->x, event->y, rop->trackvec);
+
+	/* add temp handler */
+	WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+
+	return OPERATOR_RUNNING_MODAL;
+}
+
+/************************ light paint recompute ************************/
 static int light_paint_recompute(bContext *C, wmOperator *op)
 {
-	light_paint_compute(C, 1);
+	return light_paint_compute(C, 1);
 }
 
 
@@ -724,14 +820,24 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+void PAINT_OT_light_paint_rotate(wmOperatorType *ot)
+{
+	ot->name= "Light Paint Rotate";
+	ot->idname= "PAINT_OT_light_paint_rotate";
+	
+	ot->invoke= light_paint_rotate_invoke;
+	ot->modal= light_paint_rotate_modal;
+	ot->poll= light_paint_rotate_poll;
 
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 void PAINT_OT_light_paint_recompute(struct wmOperatorType *ot)
 {
 	ot->name= "Light Paint Recompute";
 	ot->idname = "PAINT_OT_light_paint_recompute";
 
 	ot->exec= light_paint_recompute;
-	//ot->poll= light_paint_poll;
-
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }

Modified: branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_ops.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list