Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2010-03-15 07:54:31 +0300
committerMatt Ebb <matt@mke3.net>2010-03-15 07:54:31 +0300
commite38139552243865f77f2da1e78ad3b8f2291926d (patch)
treee302384eec1a76225b15165ce2ad4207700dd949 /source
parent72cc38e05d5ab11c4b14161df451e6266725b025 (diff)
Fix [#21288] Colour Ramp doesn't update output
Moved color ramp RNA to rna_color.c, was very texture-centric before.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/include/ED_node.h1
-rw-r--r--source/blender/editors/space_node/node_draw.c35
-rw-r--r--source/blender/makesrna/intern/rna_color.c214
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c32
-rw-r--r--source/blender/makesrna/intern/rna_texture.c150
5 files changed, 251 insertions, 181 deletions
diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index b7dc9bf73b5..2abac1d502c 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -40,6 +40,7 @@ void ED_init_node_butfuncs(void);
/* node_draw.c */
void ED_node_changed_update(struct ID *id, struct bNode *node);
+void ED_node_generic_update(struct Main *bmain, struct Scene *scene, struct bNodeTree *ntree, struct bNode *node);
/* node_edit.c */
void ED_node_shader_default(struct Material *ma);
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index 5928e5cf20e..3f53b80bd22 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -121,6 +121,41 @@ void ED_node_changed_update(ID *id, bNode *node)
}
}
+static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
+{
+ bNode *node;
+
+ if(ntree == lookup)
+ return 1;
+
+ for(node=ntree->nodes.first; node; node=node->next)
+ if(node->type == NODE_GROUP && node->id)
+ if(has_nodetree((bNodeTree*)node->id, lookup))
+ return 1;
+
+ return 0;
+}
+
+void ED_node_generic_update(Main *bmain, Scene *scene, bNodeTree *ntree, bNode *node)
+{
+ Material *ma;
+ Tex *tex;
+ Scene *sce;
+
+ /* look through all datablocks, to support groups */
+ for(ma=bmain->mat.first; ma; ma=ma->id.next)
+ if(ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree))
+ ED_node_changed_update(&ma->id, node);
+
+ for(tex=bmain->tex.first; tex; tex=tex->id.next)
+ if(tex->nodetree && tex->use_nodes && has_nodetree(tex->nodetree, ntree))
+ ED_node_changed_update(&tex->id, node);
+
+ for(sce=bmain->scene.first; sce; sce=sce->id.next)
+ if(sce->nodetree && sce->use_nodes && has_nodetree(sce->nodetree, ntree))
+ ED_node_changed_update(&sce->id, node);
+}
+
static void do_node_internal_buttons(bContext *C, void *node_v, int event)
{
if(event==B_NODE_EXEC) {
diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c
index ee19bce6435..dc395e6ccc3 100644
--- a/source/blender/makesrna/intern/rna_color.c
+++ b/source/blender/makesrna/intern/rna_color.c
@@ -32,7 +32,21 @@
#ifdef RNA_RUNTIME
+#include "RNA_access.h"
+
+#include "DNA_material_types.h"
+#include "DNA_node_types.h"
+
+#include "MEM_guardedalloc.h"
+
#include "BKE_colortools.h"
+#include "BKE_depsgraph.h"
+#include "BKE_node.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_node.h"
static int rna_CurveMapping_curves_length(PointerRNA *ptr)
{
@@ -113,6 +127,150 @@ static void rna_CurveMapping_clipmaxy_range(PointerRNA *ptr, float *min, float *
*max= 100.0f;
}
+
+static char *rna_ColorRamp_path(PointerRNA *ptr)
+{
+ /* handle the cases where a single datablock may have 2 ramp types */
+ if (ptr->id.data) {
+ ID *id= ptr->id.data;
+
+ switch (GS(id->name)) {
+ case ID_MA: /* material has 2 cases - diffuse and specular */
+ {
+ Material *ma= (Material*)id;
+
+ if (ptr->data == ma->ramp_col)
+ return BLI_strdup("diffuse_ramp");
+ else if (ptr->data == ma->ramp_spec)
+ return BLI_strdup("specular_ramp");
+ }
+ break;
+ }
+ }
+
+ /* everything else just uses 'color_ramp' */
+ return BLI_strdup("color_ramp");
+}
+
+static char *rna_ColorRampElement_path(PointerRNA *ptr)
+{
+ PointerRNA ramp_ptr;
+ PropertyRNA *prop;
+ char *path = NULL;
+ int index;
+
+ /* helper macro for use here to try and get the path
+ * - this calls the standard code for getting a path to a texture...
+ */
+#define COLRAMP_GETPATH \
+{ \
+prop= RNA_struct_find_property(&ramp_ptr, "elements"); \
+if (prop) { \
+index= RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr); \
+if (index >= 0) { \
+char *texture_path= rna_ColorRamp_path(&ramp_ptr); \
+path= BLI_sprintfN("%s.elements[%d]", texture_path, index); \
+MEM_freeN(texture_path); \
+} \
+} \
+}
+
+ /* determine the path from the ID-block to the ramp */
+ // FIXME: this is a very slow way to do it, but it will have to suffice...
+ if (ptr->id.data) {
+ ID *id= ptr->id.data;
+
+ switch (GS(id->name)) {
+ case ID_MA: /* 2 cases for material - diffuse and spec */
+ {
+ Material *ma= (Material *)id;
+
+ /* try diffuse first */
+ if (ma->ramp_col) {
+ RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
+ COLRAMP_GETPATH;
+ }
+ /* try specular if not diffuse */
+ if (!path && ma->ramp_spec) {
+ RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
+ COLRAMP_GETPATH;
+ }
+ }
+ break;
+
+ // TODO: node trees need special attention
+ case ID_NT:
+ {
+ bNodeTree *ntree = (bNodeTree *)id;
+ bNode *node;
+
+ for(node=ntree->nodes.first; node; node=node->next) {
+ if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
+ RNA_pointer_create(id, &RNA_ColorRamp, node->storage, &ramp_ptr);
+ COLRAMP_GETPATH;
+ }
+ }
+ }
+ break;
+
+ default: /* everything else should have a "color_ramp" property */
+ {
+ /* create pointer to the ID block, and try to resolve "color_ramp" pointer */
+ RNA_id_pointer_create(id, &ramp_ptr);
+ if (RNA_path_resolve(&ramp_ptr, "color_ramp", &ramp_ptr, &prop)) {
+ COLRAMP_GETPATH;
+ }
+ }
+ }
+ }
+
+ /* cleanup the macro we defined */
+#undef COLRAMP_GETPATH
+
+ return path;
+}
+
+static void rna_ColorRamp_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ if (ptr->id.data) {
+ ID *id= ptr->id.data;
+
+ switch (GS(id->name)) {
+ case ID_MA:
+ {
+ Material *ma= ptr->id.data;
+
+ DAG_id_flush_update(&ma->id, 0);
+ WM_main_add_notifier(NC_MATERIAL|ND_SHADING_DRAW, ma);
+ }
+ break;
+ case ID_NT:
+ {
+ bNodeTree *ntree = (bNodeTree *)id;
+ bNode *node;
+
+ for(node=ntree->nodes.first; node; node=node->next) {
+ if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
+ ED_node_generic_update(bmain, scene, ntree, node);
+ }
+ }
+ }
+ break;
+ case ID_TE:
+ {
+ Tex *tex= ptr->id.data;
+
+ DAG_id_flush_update(&tex->id, 0);
+ WM_main_add_notifier(NC_TEXTURE, tex);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+
#else
static void rna_def_curvemappoint(BlenderRNA *brna)
@@ -229,6 +387,60 @@ static void rna_def_curvemapping(BlenderRNA *brna)
RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
}
+static void rna_def_color_ramp_element(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "ColorRampElement", NULL);
+ RNA_def_struct_sdna(srna, "CBData");
+ RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
+ RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
+
+ prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_float_sdna(prop, NULL, "r");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Color", "");
+ RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+
+ prop= RNA_def_property(srna, "position", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_float_sdna(prop, NULL, "pos");
+ RNA_def_property_range(prop, 0, 1);
+ RNA_def_property_ui_text(prop, "Position", "");
+ RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+}
+
+static void rna_def_color_ramp(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static EnumPropertyItem prop_interpolation_items[] = {
+ {1, "EASE", 0, "Ease", ""},
+ {3, "CARDINAL", 0, "Cardinal", ""},
+ {0, "LINEAR", 0, "Linear", ""},
+ {2, "B_SPLINE", 0, "B-Spline", ""},
+ {4, "CONSTANT", 0, "Constant", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+ srna= RNA_def_struct(brna, "ColorRamp", NULL);
+ RNA_def_struct_sdna(srna, "ColorBand");
+ RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
+ RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
+
+ prop= RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
+ RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
+ RNA_def_property_struct_type(prop, "ColorRampElement");
+ RNA_def_property_ui_text(prop, "Elements", "");
+ RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+
+ prop= RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "ipotype");
+ RNA_def_property_enum_items(prop, prop_interpolation_items);
+ RNA_def_property_ui_text(prop, "Interpolation", "");
+ RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+}
+
static void rna_def_histogram(BlenderRNA *brna)
{
StructRNA *srna;
@@ -243,6 +455,8 @@ void RNA_def_color(BlenderRNA *brna)
rna_def_curvemappoint(brna);
rna_def_curvemap(brna);
rna_def_curvemapping(brna);
+ rna_def_color_ramp_element(brna);
+ rna_def_color_ramp(brna);
rna_def_histogram(brna);
}
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index ba805bd0a4f..5a05e588ece 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -118,21 +118,6 @@ static char *rna_NodeSocket_path(PointerRNA *ptr)
return NULL;
}
-static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
-{
- bNode *node;
-
- if(ntree == lookup)
- return 1;
-
- for(node=ntree->nodes.first; node; node=node->next)
- if(node->type == NODE_GROUP && node->id)
- if(has_nodetree((bNodeTree*)node->id, lookup))
- return 1;
-
- return 0;
-}
-
/* Button Set Funcs for Matte Nodes */
static void rna_Matte_t1_set(PointerRNA *ptr, float value)
{
@@ -158,22 +143,7 @@ static void rna_Matte_t2_set(PointerRNA *ptr, float value)
static void node_update(Main *bmain, Scene *scene, bNodeTree *ntree, bNode *node)
{
- Material *ma;
- Tex *tex;
- Scene *sce;
-
- /* look through all datablocks, to support groups */
- for(ma=bmain->mat.first; ma; ma=ma->id.next)
- if(ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree))
- ED_node_changed_update(&ma->id, node);
-
- for(tex=bmain->tex.first; tex; tex=tex->id.next)
- if(tex->nodetree && tex->use_nodes && has_nodetree(tex->nodetree, ntree))
- ED_node_changed_update(&tex->id, node);
-
- for(sce=bmain->scene.first; sce; sce=sce->id.next)
- if(sce->nodetree && sce->use_nodes && has_nodetree(sce->nodetree, ntree))
- ED_node_changed_update(&sce->id, node);
+ ED_node_generic_update(bmain, scene, ntree, node);
}
static void rna_Node_update(Main *bmain, Scene *scene, PointerRNA *ptr)
diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c
index 86018c996de..bdd1b710db5 100644
--- a/source/blender/makesrna/intern/rna_texture.c
+++ b/source/blender/makesrna/intern/rna_texture.c
@@ -363,156 +363,8 @@ static void rna_PointDensity_psys_set(PointerRNA *ptr, PointerRNA value)
pd->psys= BLI_findindex(&ob->particlesystem, value.data) + 1;
}
-static char *rna_ColorRamp_path(PointerRNA *ptr)
-{
- /* handle the cases where a single datablock may have 2 ramp types */
- if (ptr->id.data) {
- ID *id= ptr->id.data;
-
- switch (GS(id->name)) {
- case ID_MA: /* material has 2 cases - diffuse and specular */
- {
- Material *ma= (Material*)id;
-
- if (ptr->data == ma->ramp_col)
- return BLI_strdup("diffuse_ramp");
- else if (ptr->data == ma->ramp_spec)
- return BLI_strdup("specular_ramp");
- }
- break;
- }
- }
-
- /* everything else just uses 'color_ramp' */
- return BLI_strdup("color_ramp");
-}
-
-static char *rna_ColorRampElement_path(PointerRNA *ptr)
-{
- PointerRNA ramp_ptr;
- PropertyRNA *prop;
- char *path = NULL;
- int index;
-
- /* helper macro for use here to try and get the path
- * - this calls the standard code for getting a path to a texture...
- */
-#define COLRAMP_GETPATH \
- { \
- prop= RNA_struct_find_property(&ramp_ptr, "elements"); \
- if (prop) { \
- index= RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr); \
- if (index >= 0) { \
- char *texture_path= rna_ColorRamp_path(&ramp_ptr); \
- path= BLI_sprintfN("%s.elements[%d]", texture_path, index); \
- MEM_freeN(texture_path); \
- } \
- } \
- }
-
- /* determine the path from the ID-block to the ramp */
- // FIXME: this is a very slow way to do it, but it will have to suffice...
- if (ptr->id.data) {
- ID *id= ptr->id.data;
-
- switch (GS(id->name)) {
- case ID_MA: /* 2 cases for material - diffuse and spec */
- {
- Material *ma= (Material *)id;
-
- /* try diffuse first */
- if (ma->ramp_col) {
- RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
- COLRAMP_GETPATH;
- }
- /* try specular if not diffuse */
- if (!path && ma->ramp_spec) {
- RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
- COLRAMP_GETPATH;
- }
- }
- break;
-
- // TODO: node trees need special attention
- case ID_NT:
- {
- // FIXME: we'll probably have to loop over nodes until we find one that uses the color ramp
- }
- break;
-
- default: /* everything else should have a "color_ramp" property */
- {
- /* create pointer to the ID block, and try to resolve "color_ramp" pointer */
- RNA_id_pointer_create(id, &ramp_ptr);
- if (RNA_path_resolve(&ramp_ptr, "color_ramp", &ramp_ptr, &prop)) {
- COLRAMP_GETPATH;
- }
- }
- }
- }
-
- /* cleanup the macro we defined */
-#undef COLRAMP_GETPATH
-
- return path;
-}
-
#else
-static void rna_def_color_ramp_element(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna= RNA_def_struct(brna, "ColorRampElement", NULL);
- RNA_def_struct_sdna(srna, "CBData");
- RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
- RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
-
- prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "r");
- RNA_def_property_array(prop, 4);
- RNA_def_property_ui_text(prop, "Color", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop= RNA_def_property(srna, "position", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "pos");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Position", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-}
-
-static void rna_def_color_ramp(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static EnumPropertyItem prop_interpolation_items[] = {
- {1, "EASE", 0, "Ease", ""},
- {3, "CARDINAL", 0, "Cardinal", ""},
- {0, "LINEAR", 0, "Linear", ""},
- {2, "B_SPLINE", 0, "B-Spline", ""},
- {4, "CONSTANT", 0, "Constant", ""},
- {0, NULL, 0, NULL, NULL}};
-
- srna= RNA_def_struct(brna, "ColorRamp", NULL);
- RNA_def_struct_sdna(srna, "ColorBand");
- RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
- RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
-
- prop= RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
- RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
- RNA_def_property_struct_type(prop, "ColorRampElement");
- RNA_def_property_ui_text(prop, "Elements", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop= RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ipotype");
- RNA_def_property_enum_items(prop, prop_interpolation_items);
- RNA_def_property_ui_text(prop, "Interpolation", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-}
-
static void rna_def_texmapping(BlenderRNA *brna)
{
StructRNA *srna;
@@ -1912,8 +1764,6 @@ void RNA_def_texture(BlenderRNA *brna)
rna_def_texture(brna);
rna_def_mtex(brna);
rna_def_environment_map(brna);
- rna_def_color_ramp(brna);
- rna_def_color_ramp_element(brna);
rna_def_texmapping(brna);
}