-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathui.py
266 lines (202 loc) · 8.06 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import os
import bpy
from .pbr_utils import PbrSettings
from . import pman
from . import operators
class PandaButtonsPanel:
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
COMPAT_ENGINES = {'PANDA'}
@classmethod
def poll(cls, context):
return context.scene.render.engine in cls.COMPAT_ENGINES
class PandaRender_PT_project(PandaButtonsPanel, bpy.types.Panel):
bl_label = "Project Settings"
bl_context = "render"
def draw_with_config(self, context, _config):
layout = self.layout
project_settings = context.scene.panda_project
layout.prop(project_settings, 'project_name')
layout.prop(project_settings, 'renderer')
layout.prop(project_settings, 'pbr_materials')
layout.prop(project_settings, 'python_binary')
layout.operator(operators.UpdateProject.bl_idname)
def draw_no_config(self, _context):
layout = self.layout
layout.label(text="No config file detected")
def draw(self, context):
confdir = os.path.dirname(bpy.data.filepath) if bpy.data.filepath else None
if pman.config_exists(confdir):
self.draw_with_config(context, pman.get_config(confdir))
else:
self.draw_no_config(context)
layout = self.layout
layout.operator(operators.CreateProject.bl_idname)
layout.operator(operators.SwitchProject.bl_idname)
class PandaRender_PT_build(PandaButtonsPanel, bpy.types.Panel):
bl_label = "Build Settings"
bl_context = "render"
@classmethod
def poll(cls, context):
confdir = os.path.dirname(bpy.data.filepath) if bpy.data.filepath else None
return PandaButtonsPanel.poll(context) and pman.config_exists(confdir)
def draw(self, context):
layout = self.layout
project_settings = context.scene.panda_project
layout.prop(project_settings, 'asset_dir')
layout.prop(project_settings, 'export_dir')
layout.operator(operators.BuildProject.bl_idname)
class PandaRender_PT_run(PandaButtonsPanel, bpy.types.Panel):
bl_label = "Run Settings"
bl_context = "render"
@classmethod
def poll(cls, context):
confdir = os.path.dirname(bpy.data.filepath) if bpy.data.filepath else None
return PandaButtonsPanel.poll(context) and pman.config_exists(confdir)
def draw(self, context):
layout = self.layout
project_settings = context.scene.panda_project
layout.prop(project_settings, 'auto_save')
layout.prop(project_settings, 'auto_build')
layout.operator(operators.RunProject.bl_idname)
class Panda_PT_context_material(PandaButtonsPanel, bpy.types.Panel):
bl_label = ""
bl_context = "material"
bl_options = {'HIDE_HEADER'}
@classmethod
def poll(cls, context):
return (context.material or context.object) and PandaButtonsPanel.poll(context)
def draw(self, context):
layout = self.layout
mat = context.material
ob = context.object
slot = context.material_slot
space = context.space_data
is_sortable = len(ob.material_slots) > 1
if ob:
rows = 1
if is_sortable:
rows = 4
row = layout.row()
row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
col = row.column(align=True)
col.operator("object.material_slot_add", icon='ZOOMIN', text="")
col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
if is_sortable:
col.separator()
col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
if ob.mode == 'EDIT':
row = layout.row(align=True)
row.operator("object.material_slot_assign", text="Assign")
row.operator("object.material_slot_select", text="Select")
row.operator("object.material_slot_deselect", text="Deselect")
split = layout.split(percentage=0.65)
if ob:
split.template_ID(ob, "active_material", new="material.new")
row = split.row()
if slot:
row.prop(slot, "link", text="")
else:
row.label()
elif mat:
split.template_ID(space, "pin_id")
split.separator()
class PandaMaterial_PT_basic(PandaButtonsPanel, bpy.types.Panel):
bl_label = "Basic Material"
bl_context = "material"
@classmethod
def poll(cls, context):
return context.material and PandaButtonsPanel.poll(context)
def draw(self, context):
layout = self.layout
mat = context.material
layout.label(text="Diffuse:")
split = layout.split()
col = split.column()
col.prop(mat, "diffuse_color", text="")
col = split.column()
col.prop(mat, "diffuse_intensity", text="Intensity")
layout.label(text="Specular:")
split = layout.split()
col = split.column()
col.prop(mat, "specular_color", text="")
col = split.column()
col.prop(mat, "specular_intensity", text="Intensity")
layout.prop(mat, "specular_hardness")
layout.prop(mat, "emit", text="Emit")
layout.prop(mat, "ambient", text="Ambient")
class PandaCamera_PT_lens(PandaButtonsPanel, bpy.types.Panel):
bl_label = "Lens"
bl_context = "data"
@classmethod
def poll(cls, context):
return context.camera and PandaButtonsPanel.poll(context)
def draw(self, context):
layout = self.layout
camera = context.camera
layout.prop(camera, "type", text="")
if camera.type == "PERSP":
split = layout.split()
col = split.column()
col.prop(camera, "lens")
col = split.column()
col.prop(camera, "lens_unit", text="")
elif camera.type == "ORTHO":
layout.prop(camera, "ortho_scale")
else:
layout.label("Not supported")
class PandaPhysics_PT_add(PandaButtonsPanel, bpy.types.Panel):
bl_label = ""
bl_options = {'HIDE_HEADER'}
bl_context = "physics"
@classmethod
def poll(cls, context):
return PandaButtonsPanel.poll(context) and context.object
def draw(self, context):
layout = self.layout
obj = context.object
if obj.rigid_body:
layout.operator('rigidbody.object_remove', text="Remove Rigid Body Physics")
else:
layout.operator('rigidbody.object_add', text="Add Rigid Body Physics")
def get_panels():
panels = [
"DATA_PT_camera_display",
"DATA_PT_camera_safe_areas",
"DATA_PT_context_lamp",
"DATA_PT_lamp",
"DATA_PT_context_mesh",
"DATA_PT_normals",
"DATA_PT_texture_space",
"DATA_PT_vertex_groups",
"DATA_PT_shape_keys",
"DATA_PT_uv_texture",
"DATA_PT_vertex_colors",
"DATA_PT_customdata",
"WORLD_PT_preview",
"WORLD_PT_world",
"TEXTURE_PT_context_texture",
"TEXTURE_PT_preview",
"TEXTURE_PT_colors",
"TEXTURE_PT_image",
"TEXTURE_PT_image_sampling",
"TEXTURE_PT_image_mapping",
"TEXTURE_PT_mapping",
"TEXTURE_PT_influence",
"PHYSICS_PT_rigid_body",
"PHYSICS_PT_rigid_body_collisions",
]
return [getattr(bpy.types, p) for p in panels if hasattr(bpy.types, p)]
def register():
for panel in get_panels():
panel.COMPAT_ENGINES.add('PANDA')
if not hasattr(bpy.types.Material, 'pbr_export_settings'):
bpy.types.Material.pbr_export_settings = bpy.props.PointerProperty(type=PbrSettings)
def unregister():
for panel in get_panels():
if 'PANDA' in panel.COMPAT_ENGINES:
panel.COMPAT_ENGINES.remove('PANDA')
if hasattr(bpy.types.Material, 'pbr_export_settings'):
del bpy.types.Material.pbr_export_settings