Skip to content

Commit 4ad0a30

Browse files
committed
imported material context from cycles
1 parent 00ea683 commit 4ad0a30

1 file changed

Lines changed: 82 additions & 24 deletions

File tree

src/blender-addon/leaf/material.py

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77
IntProperty,
88
PointerProperty)
99

10-
class LeafMaterialSettings(bpy.types.PropertyGroup):
11-
@classmethod
12-
def register(cls):
13-
bpy.types.Material.leaf = PointerProperty(
14-
name="Leaf Material Settings",
15-
description="Leaf material settings",
16-
type=cls,
17-
)
18-
cls.metalness = FloatProperty(
19-
name="Metalness",
20-
description="0: dielectric, 1: metal",
21-
min=0.0, max=1.0,
22-
default=0.0,
23-
)
24-
cls.roughness = FloatProperty(
25-
name="Roughness",
26-
description="0: smooth, 1: rough",
27-
min=0.0, max=1.0,
28-
default=0.5,
29-
)
30-
31-
@classmethod
32-
def unregister(cls):
33-
del bpy.types.Material.leaf
10+
class LeafMaterialSettings(bpy.types.PropertyGroup):
11+
@classmethod
12+
def register(cls):
13+
bpy.types.Material.leaf = PointerProperty(
14+
name="Leaf Material Settings",
15+
description="Leaf material settings",
16+
type=cls,
17+
)
18+
cls.metalness = FloatProperty(
19+
name="Metalness",
20+
description="0: dielectric, 1: metal",
21+
min=0.0, max=1.0,
22+
default=0.0,
23+
)
24+
cls.roughness = FloatProperty(
25+
name="Roughness",
26+
description="0: smooth, 1: rough",
27+
min=0.0, max=1.0,
28+
default=0.5,
29+
)
30+
31+
@classmethod
32+
def unregister(cls):
33+
del bpy.types.Material.leaf
3434

3535
class LeafMaterialButtonsPanel():
3636
bl_space_type = "PROPERTIES"
@@ -43,6 +43,64 @@ def poll(cls, context):
4343
rd = context.scene.render
4444
return rd.engine in cls.COMPAT_ENGINES
4545

46+
class LeafMaterial_PT_context(LeafMaterialButtonsPanel, Panel):
47+
bl_label = ""
48+
bl_options = {'HIDE_HEADER'}
49+
50+
@classmethod
51+
def poll(cls, context):
52+
return (context.material or context.object) and LeafMaterialButtonsPanel.poll(context)
53+
54+
def draw(self, context):
55+
layout = self.layout
56+
57+
mat = context.material
58+
ob = context.object
59+
slot = context.material_slot
60+
space = context.space_data
61+
is_sortable = len(ob.material_slots) > 1
62+
63+
if ob:
64+
rows = 1
65+
if (is_sortable):
66+
rows = 4
67+
68+
row = layout.row()
69+
70+
row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
71+
72+
col = row.column(align=True)
73+
col.operator("object.material_slot_add", icon='ZOOMIN', text="")
74+
col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
75+
76+
col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
77+
78+
if is_sortable:
79+
col.separator()
80+
81+
col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
82+
col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
83+
84+
if ob.mode == 'EDIT':
85+
row = layout.row(align=True)
86+
row.operator("object.material_slot_assign", text="Assign")
87+
row.operator("object.material_slot_select", text="Select")
88+
row.operator("object.material_slot_deselect", text="Deselect")
89+
90+
split = layout.split(percentage=0.65)
91+
92+
if ob:
93+
split.template_ID(ob, "active_material", new="material.new")
94+
row = split.row()
95+
96+
if slot:
97+
row.prop(slot, "link", text="")
98+
else:
99+
row.label()
100+
elif mat:
101+
split.template_ID(space, "pin_id")
102+
split.separator()
103+
46104
class LeafMaterial_PT_surface(LeafMaterialButtonsPanel, Panel):
47105
bl_label = "Surface"
48106

0 commit comments

Comments
 (0)