[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21392] branches/soc-2009-yukishiro/source /blender: node button for lightenv node

Jingyuan Huang jingyuan.huang at gmail.com
Mon Jul 6 22:07:01 CEST 2009


Revision: 21392
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21392
Author:   yukishiro
Date:     2009-07-06 22:07:00 +0200 (Mon, 06 Jul 2009)

Log Message:
-----------
node button for lightenv node

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h
    branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/library.c
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
    branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.h

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h	2009-07-06 20:07:00 UTC (rev 21392)
@@ -36,12 +36,11 @@
 #endif
 
 struct LightEnv;
-struct Scene;
 struct Image;
 
 void init_def_lightenv(void);
 void free_lightenv(struct LightEnv *env); 
-void add_lightenv(struct Scene *scene, char *name);
+struct LightEnv* add_lightenv(char *name);
 void save_lightenv(struct LightEnv *env, char *image_name);
 
 void update_light_func(struct LightEnv *env);

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h	2009-07-06 20:07:00 UTC (rev 21392)
@@ -441,4 +441,6 @@
 void init_nodesystem(void);
 void free_nodesystem(void);
 
+extern struct ListBase node_all_light;
+
 #endif

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/library.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/library.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/library.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -739,6 +739,7 @@
 			case ID_IM: /* fall through */
 			case ID_WO: /* fall through */
 			case ID_LA: /* fall through */
+			case ID_LE: /* fall through */
 				sprintf(buf, "%%i%d", BKE_icon_getid(id) );
 				BLI_dynstr_append(pupds, buf);
 				break;

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -112,7 +112,7 @@
 }
 
 
-void add_lightenv(Scene *scene, char *name)
+LightEnv * add_lightenv(char *name)
 {
 	LightEnv *env;
 
@@ -124,6 +124,6 @@
 	env->output_width = env->output_height = 512;
 	SH_computeLightCoefficients(env);
 
-	scene->lightenv = env;
+	return env;
 }
 

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -3078,6 +3078,7 @@
 	nodeRegisterType(ntypelist, &lgt_node_image);
 	nodeRegisterType(ntypelist, &lgt_node_output_file);
 }
+
 static void remove_dynamic_typeinfos(ListBase *list)
 {
 	bNodeType *ntype= list->first;
@@ -3126,4 +3127,5 @@
 	remove_dynamic_typeinfos(&node_all_shaders);
 	BLI_freelistN(&node_all_shaders);
 	BLI_freelistN(&node_all_textures);
+	BLI_freelistN(&node_all_light);
 }

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-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -108,7 +108,7 @@
 	sj->do_update= do_update;
 	
 	if (sj->scene->lightenv == NULL) 
-		add_lightenv(sj->scene, "LightEnv");
+		sj->scene->lightenv = add_lightenv("LightEnv");
 
 	SH_computeSceneCoefficients(sj->scene, sj->mask, 0, sj->recompute);
 }
@@ -270,7 +270,7 @@
 
 		//light_paint_compute(C, 0);
 		if (scene->lightenv == NULL) 
-			add_lightenv(scene, "LightEnv");
+			scene->lightenv = add_lightenv("LightEnv");
 		SH_computeSceneCoefficients(scene, 
 			get_viewedit_datamask(CTX_wm_screen(C)), 0, 0);
 		WM_event_add_notifier(C, NC_LIGHTENV|ND_SH_RESULT, NULL);

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -51,6 +51,7 @@
 #include "DNA_texture_types.h"
 #include "DNA_text_types.h"
 #include "DNA_userdef_types.h"
+#include "DNA_lightenv_types.h"
 
 #include "BKE_context.h"
 #include "BKE_curve.h"
@@ -2364,6 +2365,89 @@
 	}
 }
 
+static void node_browse_lightenv_cb(bContext *C, void *ntree_v, void *node_v)
+{
+	bNodeTree *ntree = ntree_v;
+	bNode *node = node_v;
+
+	if (node->menunr<1) return;
+
+	if (node->menunr==32767) {	/* code for Add New */
+		if (node->id) {
+			LightEnv *env = (LightEnv *)node->id;
+			env->id.us--;
+			env = add_lightenv("LightEnvNode");
+			node->id= (ID *)env;
+		}
+		else node->id = (ID *)add_lightenv("LightEnvNode");
+	}
+	else {
+		if(node->id) node->id->us--;
+		node->id= BLI_findlink(&G.main->lightenv, node->menunr-1);
+		id_us_plus(node->id);
+	}
+	BLI_strncpy(node->name, node->id->name+2, 21);
+	nodeSetActive(ntree, node);
+}
+
+static void node_new_lightenv_cb(bContext *C, void *ntree_v, void *node_v)
+{
+	bNodeTree *ntree = ntree_v;
+	bNode *node = node_v;
+
+	node->id = (ID *)add_lightenv("LightEnvNode");
+	BLI_strncpy(node->name, node->id->name+2, 21);
+	nodeSetActive(ntree, node);
+}
+
+static int node_buts_lightenv(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
+{
+	if(block) {
+		uiBut *bt;
+		char *strp;
+
+		/* browse button lightenv */
+		uiBlockBeginAlign(block);
+		IDnames_to_pupstring(&strp, NULL, "ADD NEW %x32767", &(G.main->lightenv), NULL, NULL);
+		node->menunr= 0;
+		bt= uiDefButS(block, MENU, B_NOP, strp,
+			butr->xmin, butr->ymin, 19, 19, &node->menunr, 0, 0, 0, 0, 
+			"Browse existing light envs or add NEW");
+		uiButSetFunc(bt, node_browse_lightenv_cb, ntree, node);
+		if(strp) MEM_freeN(strp);
+
+		if(node->id == NULL) {
+			bt= uiDefBut(block, BUT, B_NOP, "Add New",
+				butr->xmin+19, butr->ymin, (short)(butr->xmax-butr->xmin-19.0f), 19,
+				NULL, 0.0, 0.0, 0.0, 0, "Add new LightEnv");
+			uiButSetFunc(bt, node_new_lightenv_cb, ntree, node);
+		} else {
+			/* name button */
+			short width= (short)(butr->xmax-butr->xmin-19.0f);
+			bt= uiDefBut(block, TEX, B_NOP, "LE:",
+				butr->xmin+19, butr->ymin, width, 19, 
+				node->id->name+2, 0.0, 19.0, 0, 0, "LightEnv name");
+			uiButSetFunc(bt, node_ID_title_cb, node, NULL);
+		}
+		uiBlockEndAlign(block);
+	}
+
+	return 30; // XXX
+}
+
+static void node_light_set_butfunc(bNodeType *ntype)
+{
+	switch(ntype->type) {
+		case LGT_NODE_LIGHTENV:
+			ntype->butfunc= node_buts_lightenv;
+			break;
+		case LGT_NODE_IMAGE:
+			break;
+		case LGT_NODE_OUTPUT_FILE:
+			break;
+	}
+}
+
 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
 
 void ED_init_node_butfuncs(void)
@@ -2387,6 +2471,11 @@
 		node_texture_set_butfunc(ntype);
 		ntype= ntype->next;
 	}
+	ntype = node_all_light.first;
+	while(ntype) {
+		node_light_set_butfunc(ntype);
+		ntype= ntype->next;
+	}
 }
 
 /* ************** Generic drawing ************** */

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -2331,10 +2331,10 @@
 	int num_sh = (env->degree + 1) * (env->degree + 1);
 	
 	if (mco == NULL) {
-		printf("WRONG!\N");
+		printf("WRONG!\n");
 		return;
 	}
-	if (env == NULL) add_lightenv(scene, "LightEnv");
+	if (env == NULL) scene->lightenv = add_lightenv("LightEnv");
 	
 	for (i=0; i<totface; i++, mf++) {
 		calc_sh_vert_color(num_sh, ob, mf->v1, mf->mat_nr, mco, env->shcoeffs, &shcol[(i*4 + 0) * 4]);

Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -28,19 +28,32 @@
 
 #include "../TEX_util.h"
 
-static bNodeSocketType inputs[]= {
-	{ SOCK_RGBA, 1, "Color", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
-	{ -1, 0, "" }
-};
-
 static bNodeSocketType outputs[]= {
 	{ SOCK_RGBA, 0, "Color", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f },
 	{ -1, 0, "" }
 };
 
+//static void lgt_do_preview(bNode *node, bNodeStack *ns, LightCallData *cdata)
+//{
+//	LightEnv *env;
+//	bNodePreview *preview;
+//	int x, y;
+//
+//	if(!(node->typeinfo->flag & NODE_PREVIEW))
+//		return;
+//
+//	init_preview(node);
+//	preview = node->preview;
+//
+//	SH_lightProbePreview(env, preview->xsize, preview->ysize,
+//		0, 0, preview->xsize, preview->ysize, preview->rect);
+//
+//			//tex_input_rgba(result, ns, cdata->coord, cdata->thread);
+//}
+
 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 {
-
+	// only out[0]
 }
 
 
@@ -50,7 +63,7 @@
 	/* name        */	"Light Environment",
 	/* width+range */	120, 80, 240,
 	/* class+opts  */	NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW,
-	/* input sock  */	inputs,
+	/* input sock  */	NULL,
 	/* output sock */	outputs,
 	/* storage     */	"",
 	/* execfunc    */	exec,

Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.c	2009-07-06 19:45:00 UTC (rev 21391)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.c	2009-07-06 20:07:00 UTC (rev 21392)
@@ -0,0 +1,60 @@
+/**
+ * $Id: 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list