Material buttons now view the active node material shading settings.
Selecting a material in the node tree sets this as the active material and the buttons view redraws. Added rna prop material.active_node_material Currently its not clear what settings are used by the node material and the base material (needs some tedious research) so I made most panels use the node material with the exceptions of volumetrics, physics and halo settings. We'll probably need to split the panels up to do this properly.
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
|
||||
import bpy
|
||||
|
||||
def active_node_mat(mat):
|
||||
# TODO, 2.4x has a pipeline section, for 2.5 we need to communicate
|
||||
# which settings from node-materials are used
|
||||
if mat:
|
||||
mat_node = mat.active_node_material
|
||||
if mat_node:
|
||||
return mat_node
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class MaterialButtonsPanel(bpy.types.Panel):
|
||||
__space_type__ = 'PROPERTIES'
|
||||
__region_type__ = 'WINDOW'
|
||||
@@ -74,14 +85,14 @@ class MATERIAL_PT_shading(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE', 'HALO')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
|
||||
if mat.type in ('SURFACE', 'WIRE'):
|
||||
split = layout.split()
|
||||
@@ -117,7 +128,7 @@ class MATERIAL_PT_strand(MaterialButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = context.material # dont use node material
|
||||
tan = mat.strand
|
||||
|
||||
split = layout.split()
|
||||
@@ -152,7 +163,7 @@ class MATERIAL_PT_physics(MaterialButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
phys = context.material.physics
|
||||
phys = context.material.physics # dont use node material
|
||||
|
||||
split = layout.split()
|
||||
|
||||
@@ -171,14 +182,14 @@ class MATERIAL_PT_options(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE', 'HALO')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
|
||||
split = layout.split()
|
||||
|
||||
@@ -211,14 +222,14 @@ class MATERIAL_PT_shadow(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
|
||||
split = layout.split()
|
||||
|
||||
@@ -244,14 +255,14 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
|
||||
split = layout.split()
|
||||
|
||||
@@ -298,14 +309,14 @@ class MATERIAL_PT_specular(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
|
||||
layout.active = (not mat.shadeless)
|
||||
|
||||
@@ -351,12 +362,12 @@ class MATERIAL_PT_sss(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw_header(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
sss = mat.subsurface_scattering
|
||||
|
||||
self.layout.active = (not mat.shadeless)
|
||||
@@ -365,7 +376,7 @@ class MATERIAL_PT_sss(MaterialButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
sss = mat.subsurface_scattering
|
||||
|
||||
layout.active = sss.enabled
|
||||
@@ -396,19 +407,19 @@ class MATERIAL_PT_mirror(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw_header(self, context):
|
||||
raym = context.material.raytrace_mirror
|
||||
raym = active_node_mat(context.material).raytrace_mirror
|
||||
|
||||
self.layout.itemR(raym, "enabled", text="")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
raym = mat.raytrace_mirror
|
||||
|
||||
layout.active = raym.enabled
|
||||
@@ -451,19 +462,19 @@ class MATERIAL_PT_transp(MaterialButtonsPanel):
|
||||
COMPAT_ENGINES = set(['BLENDER_RENDER'])
|
||||
|
||||
def poll(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
engine = context.scene.render_data.engine
|
||||
return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in self.COMPAT_ENGINES)
|
||||
|
||||
def draw_header(self, context):
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
|
||||
self.layout.itemR(mat, "transparency", text="")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = active_node_mat(context.material)
|
||||
rayt = mat.raytrace_transparency
|
||||
|
||||
row = layout.row()
|
||||
@@ -517,7 +528,7 @@ class MATERIAL_PT_halo(MaterialButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = context.material # dont use node material
|
||||
halo = mat.halo
|
||||
|
||||
split = layout.split()
|
||||
@@ -569,7 +580,7 @@ class MATERIAL_PT_flare(MaterialButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = context.material # dont use node material
|
||||
halo = mat.halo
|
||||
|
||||
layout.active = halo.flare_mode
|
||||
@@ -618,8 +629,7 @@ class MATERIAL_PT_volume_density(VolumeButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
vol = context.material.volume
|
||||
vol = context.material.volume # dont use node material
|
||||
|
||||
split = layout.split()
|
||||
row = split.row()
|
||||
@@ -635,7 +645,7 @@ class MATERIAL_PT_volume_shading(VolumeButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
vol = context.material.volume
|
||||
vol = context.material.volume # dont use node material
|
||||
|
||||
split = layout.split()
|
||||
|
||||
@@ -660,7 +670,7 @@ class MATERIAL_PT_volume_lighting(VolumeButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
vol = context.material.volume
|
||||
vol = context.material.volume # dont use node material
|
||||
|
||||
split = layout.split()
|
||||
|
||||
@@ -695,7 +705,7 @@ class MATERIAL_PT_volume_transp(VolumeButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
mat = context.material
|
||||
mat = context.material # dont use node material
|
||||
|
||||
layout.itemR(mat, "transparency_method", expand=True)
|
||||
|
||||
@@ -707,7 +717,7 @@ class MATERIAL_PT_volume_integration(VolumeButtonsPanel):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
vol = context.material.volume
|
||||
vol = context.material.volume # dont use node material
|
||||
|
||||
split = layout.split()
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@ int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
|
||||
void nodeSetActive(struct bNodeTree *ntree, struct bNode *node);
|
||||
struct bNode *nodeGetActive(struct bNodeTree *ntree);
|
||||
struct bNode *nodeGetActiveID(struct bNodeTree *ntree, short idtype);
|
||||
int nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id);
|
||||
void nodeClearActiveID(struct bNodeTree *ntree, short idtype);
|
||||
|
||||
void NodeTagChanged(struct bNodeTree *ntree, struct bNode *node);
|
||||
|
||||
@@ -1575,6 +1575,37 @@ bNode *nodeGetActiveID(bNodeTree *ntree, short idtype)
|
||||
return node;
|
||||
}
|
||||
|
||||
int nodeSetActiveID(bNodeTree *ntree, short idtype, ID *id)
|
||||
{
|
||||
bNode *node;
|
||||
int ok= FALSE;
|
||||
|
||||
if(ntree==NULL) return ok;
|
||||
|
||||
/* check for group edit */
|
||||
for(node= ntree->nodes.first; node; node= node->next)
|
||||
if(node->flag & NODE_GROUP_EDIT)
|
||||
break;
|
||||
|
||||
if(node)
|
||||
ntree= (bNodeTree*)node->id;
|
||||
|
||||
/* now find active node with this id */
|
||||
for(node= ntree->nodes.first; node; node= node->next) {
|
||||
if(node->id && GS(node->id->name)==idtype) {
|
||||
if(id && ok==FALSE && node->id==id) {
|
||||
node->flag |= NODE_ACTIVE_ID;
|
||||
ok= TRUE;
|
||||
} else {
|
||||
node->flag &= ~NODE_ACTIVE_ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
/* two active flags, ID nodes have special flag for buttons display */
|
||||
void nodeClearActiveID(bNodeTree *ntree, short idtype)
|
||||
{
|
||||
|
||||
@@ -1100,17 +1100,15 @@ static struct MultiresModifierData *sculpt_multires_active(Object *ob)
|
||||
|
||||
for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) {
|
||||
if(md->type == eModifierType_Multires) {
|
||||
MultiresModifierData *mmd;
|
||||
MultiresModifierData *mmd= (MultiresModifierData*)md;
|
||||
|
||||
/* Check if any of the modifiers after multires are active
|
||||
* if not it can use the multires struct */
|
||||
ModifierData *md_next;
|
||||
for (md_next= md->next; md_next; md_next= md_next->next) {
|
||||
if(md_next->mode & eModifierMode_Realtime)
|
||||
for (md= md->next; md; md= md->next) {
|
||||
if(md->mode & eModifierMode_Realtime)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mmd = (MultiresModifierData*)md;
|
||||
if(mmd->lvl != 1)
|
||||
return mmd;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
#include "BLI_rect.h"
|
||||
|
||||
@@ -55,7 +56,7 @@
|
||||
|
||||
#include "node_intern.h"
|
||||
|
||||
static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short extend)
|
||||
static bNode *node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short extend)
|
||||
{
|
||||
bNode *node;
|
||||
float mx, my;
|
||||
@@ -101,7 +102,10 @@ static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short
|
||||
;// node_link_viewer(snode, node);
|
||||
|
||||
//std_rmouse_transform(node_transform_ext); /* does undo push for select */
|
||||
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static int node_select_exec(bContext *C, wmOperator *op)
|
||||
@@ -112,6 +116,7 @@ static int node_select_exec(bContext *C, wmOperator *op)
|
||||
int select_type;
|
||||
short mval[2];
|
||||
short extend;
|
||||
bNode *node= NULL;
|
||||
|
||||
select_type = RNA_enum_get(op->ptr, "select_type");
|
||||
|
||||
@@ -120,12 +125,20 @@ static int node_select_exec(bContext *C, wmOperator *op)
|
||||
mval[0] = RNA_int_get(op->ptr, "mouse_x");
|
||||
mval[1] = RNA_int_get(op->ptr, "mouse_y");
|
||||
extend = RNA_boolean_get(op->ptr, "extend");
|
||||
node_mouse_select(snode, ar, mval, extend);
|
||||
node= node_mouse_select(snode, ar, mval, extend);
|
||||
break;
|
||||
}
|
||||
|
||||
/* need refresh/a notifier vs compo notifier */
|
||||
// XXX WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL); /* Do we need to pass the scene? */
|
||||
|
||||
/* WATCH THIS, there are a few other ways to change the active material */
|
||||
if(node) {
|
||||
if (node->id && GS(node->id->name)== ID_MA) {
|
||||
WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING_DRAW, node->id);
|
||||
}
|
||||
}
|
||||
|
||||
ED_region_tag_redraw(ar);
|
||||
|
||||
/* allow tweak event to work too */
|
||||
|
||||
@@ -54,6 +54,8 @@ static EnumPropertyItem prop_texture_coordinates_items[] = {
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_node_types.h"
|
||||
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_texture.h"
|
||||
@@ -152,6 +154,31 @@ static void rna_Material_active_texture_set(PointerRNA *ptr, PointerRNA value)
|
||||
}
|
||||
}
|
||||
|
||||
static PointerRNA rna_Material_active_node_material_get(PointerRNA *ptr)
|
||||
{
|
||||
Material *ma= (Material*)ptr->data;
|
||||
Material *ma_node= NULL;
|
||||
|
||||
/* used in buttons to check context, also checks for edited groups */
|
||||
|
||||
if(ma && ma->use_nodes && ma->nodetree) {
|
||||
bNode *node= nodeGetActiveID(ma->nodetree, ID_MA);
|
||||
|
||||
if(node)
|
||||
ma_node= (Material *)node->id;
|
||||
}
|
||||
|
||||
return rna_pointer_inherit_refine(ptr, &RNA_Material, ma_node);
|
||||
}
|
||||
|
||||
static void rna_Material_active_node_material_set(PointerRNA *ptr, PointerRNA value)
|
||||
{
|
||||
Material *ma= (Material*)ptr->data;
|
||||
Material *ma_act= value.data;
|
||||
|
||||
nodeSetActiveID(ma->nodetree, ID_MA, ma_act);
|
||||
}
|
||||
|
||||
static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max)
|
||||
{
|
||||
Material *ma= (Material*)ptr->id.data;
|
||||
@@ -1690,6 +1717,13 @@ void RNA_def_material(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the material.");
|
||||
RNA_def_property_update(prop, NC_MATERIAL, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "active_node_material", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_struct_type(prop, "Material");
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_pointer_funcs(prop, "rna_Material_active_node_material_get", "rna_Material_active_node_material_set", NULL);
|
||||
RNA_def_property_ui_text(prop, "Material", "Active node material.");
|
||||
RNA_def_property_update(prop, NC_MATERIAL, NULL);
|
||||
|
||||
/* common */
|
||||
rna_def_animdata_common(srna);
|
||||
rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
|
||||
|
||||
Reference in New Issue
Block a user