UI: add light/world settings in shader node editor.

Material was already there. Implementation was changed so it's just a
single line of code to adapt a panel to the node editor.
This commit is contained in:
2019-03-17 17:52:05 +01:00
parent f79ad42808
commit df96455c55
5 changed files with 96 additions and 109 deletions

View File

@@ -50,14 +50,18 @@ class CyclesButtonsPanel:
return context.engine in cls.COMPAT_ENGINES
class CyclesNodeButtonsPanel:
bl_space_type = "NODE_EDITOR"
bl_region_type = "UI"
COMPAT_ENGINES = {'CYCLES'}
# Adapt properties editor panel to display in node editor. We have to
# copy the class rather than inherit due to the way bpy registration works.
def node_panel(cls):
node_cls = type('NODE_' + cls.__name__, cls.__bases__, dict(cls.__dict__))
@classmethod
def poll(cls, context):
return context.engine in cls.COMPAT_ENGINES
node_cls.bl_space_type = 'NODE_EDITOR'
node_cls.bl_region_type = 'UI'
node_cls.bl_category = "Node"
if hasattr(node_cls, 'bl_parent_id'):
node_cls.bl_parent_id = 'NODE_' + node_cls.bl_parent_id
return node_cls
def get_device_type(context):
@@ -1328,13 +1332,16 @@ class CYCLES_LIGHT_PT_light(CyclesButtonsPanel, Panel):
light = context.light
clamp = light.cycles
# cscene = context.scene.cycles
layout.prop(light, "type", expand=True)
layout.use_property_split = True
layout.use_property_decorate = False
if self.bl_space_type == 'PROPERTIES':
layout.row().prop(light, "type", expand=True)
layout.use_property_split = True
else:
layout.use_property_split = True
layout.row().prop(light, "type")
col = layout.column()
if light.type in {'POINT', 'SUN', 'SPOT'}:
@@ -2035,43 +2042,6 @@ class CYCLES_RENDER_PT_simplify_culling(CyclesButtonsPanel, Panel):
sub.prop(cscene, "distance_cull_margin", text="Distance")
class CYCLES_NODE_PT_settings(CyclesNodeButtonsPanel, Panel):
bl_label = "Settings"
bl_category = "Node"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
snode = context.space_data
return CyclesNodeButtonsPanel.poll(context) and \
snode.tree_type == 'ShaderNodeTree' and snode.id and \
snode.id.bl_rna.identifier == 'Material'
def draw(self, context):
material = context.space_data.id
CYCLES_MATERIAL_PT_settings.draw_shared(self, material)
class CYCLES_NODE_PT_settings_surface(CyclesNodeButtonsPanel, Panel):
bl_label = "Surface"
bl_category = "Node"
bl_parent_id = "CYCLES_NODE_PT_settings"
def draw(self, context):
material = context.space_data.id
CYCLES_MATERIAL_PT_settings_surface.draw_shared(self, material)
class CYCLES_NODE_PT_settings_volume(CyclesNodeButtonsPanel, Panel):
bl_label = "Volume"
bl_category = "Node"
bl_parent_id = "CYCLES_NODE_PT_settings"
def draw(self, context):
material = context.space_data.id
CYCLES_MATERIAL_PT_settings_volume.draw_shared(self, context, material)
def draw_device(self, context):
scene = context.scene
layout = self.layout
@@ -2118,6 +2088,8 @@ def get_panels():
'DATA_PT_spot',
'MATERIAL_PT_context_material',
'MATERIAL_PT_preview',
'NODE_DATA_PT_light',
'NODE_DATA_PT_spot',
'VIEWLAYER_PT_filter',
'VIEWLAYER_PT_layer_passes',
'RENDER_PT_post_processing',
@@ -2203,9 +2175,15 @@ classes = (
CYCLES_RENDER_PT_bake_selected_to_active,
CYCLES_RENDER_PT_bake_output,
CYCLES_RENDER_PT_debug,
CYCLES_NODE_PT_settings,
CYCLES_NODE_PT_settings_surface,
CYCLES_NODE_PT_settings_volume,
node_panel(CYCLES_MATERIAL_PT_settings),
node_panel(CYCLES_MATERIAL_PT_settings_surface),
node_panel(CYCLES_MATERIAL_PT_settings_volume),
node_panel(CYCLES_WORLD_PT_ray_visibility),
node_panel(CYCLES_WORLD_PT_settings),
node_panel(CYCLES_WORLD_PT_settings_surface),
node_panel(CYCLES_WORLD_PT_settings_volume),
node_panel(CYCLES_LIGHT_PT_light),
node_panel(CYCLES_LIGHT_PT_spot),
)

View File

@@ -69,7 +69,13 @@ class DATA_PT_light(DataButtonsPanel, Panel):
light = context.light
layout.row().prop(light, "type", expand=True)
# Compact layout for node editor.
if self.bl_space_type == 'PROPERTIES':
layout.row().prop(light, "type", expand=True)
layout.use_property_split = True
else:
layout.use_property_split = True
layout.row().prop(light, "type")
class DATA_PT_EEVEE_light(DataButtonsPanel, Panel):
@@ -80,9 +86,13 @@ class DATA_PT_EEVEE_light(DataButtonsPanel, Panel):
layout = self.layout
light = context.light
layout.row().prop(light, "type", expand=True)
layout.use_property_split = True
# Compact layout for node editor.
if self.bl_space_type == 'PROPERTIES':
layout.row().prop(light, "type", expand=True)
layout.use_property_split = True
else:
layout.use_property_split = True
layout.row().prop(light, "type")
col = layout.column()
col.prop(light, "color")

View File

@@ -206,11 +206,12 @@ class EEVEE_MATERIAL_PT_settings(MaterialButtonsPanel, Panel):
bl_context = "material"
COMPAT_ENGINES = {'BLENDER_EEVEE'}
@staticmethod
def draw_shared(self, mat):
def draw(self, context):
layout = self.layout
layout.use_property_split = True
mat = context.material
layout.prop(mat, "blend_method")
if mat.blend_method != 'OPAQUE':
@@ -228,9 +229,6 @@ class EEVEE_MATERIAL_PT_settings(MaterialButtonsPanel, Panel):
layout.prop(mat, "use_sss_translucency")
layout.prop(mat, "pass_index")
def draw(self, context):
self.draw_shared(self, context.material)
class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel):
bl_label = "Viewport Display"
@@ -242,19 +240,17 @@ class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel):
mat = context.material
return mat and not mat.grease_pencil
@staticmethod
def draw_shared(self, mat):
def draw(self, context):
layout = self.layout
layout.use_property_split = True
mat = context.material
col = layout.column()
col.prop(mat, "diffuse_color", text="Color")
col.prop(mat, "metallic")
col.prop(mat, "roughness")
def draw(self, context):
self.draw_shared(self, context.material)
classes = (
MATERIAL_MT_context_menu,

View File

@@ -30,6 +30,13 @@ from .properties_material import (
EEVEE_MATERIAL_PT_settings,
MATERIAL_PT_viewport
)
from .properties_world import (
WORLD_PT_viewport_display
)
from .properties_data_light import (
DATA_PT_light,
DATA_PT_EEVEE_light,
)
class NODE_HT_header(Header):
@@ -569,51 +576,24 @@ class NODE_PT_grease_pencil_tools(GreasePencilToolsPanel, Panel):
# toolbar, but which may not necessarily be open
class EEVEE_NODE_PT_material_settings(Panel):
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_category = "Node"
bl_label = "Settings"
COMPAT_ENGINES = {'BLENDER_EEVEE'}
@classmethod
def poll(cls, context):
snode = context.space_data
return (
(context.engine in cls.COMPAT_ENGINES) and
(snode.tree_type == 'ShaderNodeTree' and snode.id) and
(snode.id.bl_rna.identifier == 'Material')
)
def draw(self, context):
material = context.space_data.id
EEVEE_MATERIAL_PT_settings.draw_shared(self, material)
class NODE_PT_material_viewport(Panel):
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_category = "Node"
bl_label = "Viewport Display"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
snode = context.space_data
return (
(snode.tree_type == 'ShaderNodeTree' and snode.id) and
(snode.id.bl_rna.identifier == "Material")
)
def draw(self, context):
material = context.space_data.id
MATERIAL_PT_viewport.draw_shared(self, material)
def node_draw_tree_view(layout, context):
pass
# Adapt properties editor panel to display in node editor. We have to
# copy the class rather than inherit due to the way bpy registration works.
def node_panel(cls):
node_cls = type('NODE_' + cls.__name__, cls.__bases__, dict(cls.__dict__))
node_cls.bl_space_type = 'NODE_EDITOR'
node_cls.bl_region_type = 'UI'
node_cls.bl_category = "Node"
if hasattr(node_cls, 'bl_parent_id'):
node_cls.bl_parent_id = 'NODE_' + node_cls.bl_parent_id
return node_cls
classes = (
NODE_HT_header,
NODE_MT_editor_menus,
@@ -632,8 +612,11 @@ classes = (
NODE_UL_interface_sockets,
NODE_PT_grease_pencil,
NODE_PT_grease_pencil_tools,
EEVEE_NODE_PT_material_settings,
NODE_PT_material_viewport,
node_panel(EEVEE_MATERIAL_PT_settings),
node_panel(MATERIAL_PT_viewport),
node_panel(WORLD_PT_viewport_display),
node_panel(DATA_PT_light),
node_panel(DATA_PT_EEVEE_light),
)

View File

@@ -793,7 +793,9 @@ static void node_region_listener(
}
}
const char *node_context_dir[] = {"selected_nodes", "active_node", NULL};
const char *node_context_dir[] = {
"selected_nodes", "active_node", "light", "material", "world", NULL
};
static int node_context(const bContext *C, const char *member, bContextDataResult *result)
{
@@ -833,6 +835,24 @@ static int node_context(const bContext *C, const char *member, bContextDataResul
CTX_data_type_set(result, CTX_DATA_TYPE_POINTER);
return 1;
}
else if (CTX_data_equals(member, "material")) {
if (snode->id && GS(snode->id->name) == ID_MA) {
CTX_data_id_pointer_set(result, snode->id);
}
return 1;
}
else if (CTX_data_equals(member, "light")) {
if (snode->id && GS(snode->id->name) == ID_LA) {
CTX_data_id_pointer_set(result, snode->id);
}
return 1;
}
else if (CTX_data_equals(member, "world")) {
if (snode->id && GS(snode->id->name) == ID_WO) {
CTX_data_id_pointer_set(result, snode->id);
}
return 1;
}
return 0;
}