forked from prman-pixar/RenderManForBlender
-
Notifications
You must be signed in to change notification settings - Fork 2
/
operators.py
1348 lines (1083 loc) · 46.1 KB
/
operators.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ##### BEGIN MIT LICENSE BLOCK #####
#
# Copyright (c) 2015 - 2017 Pixar
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#
# ##### END MIT LICENSE BLOCK #####
import bpy
import os
import subprocess
import blf
import webbrowser
import addon_utils
from .icons.icons import load_icons
from operator import attrgetter, itemgetter
from bl_operators.presets import AddPresetBase
from bpy.props import PointerProperty, StringProperty, BoolProperty, \
EnumProperty, IntProperty, FloatProperty, FloatVectorProperty, \
CollectionProperty
from bpy_extras.io_utils import ExportHelper
## These should be removed
from .util import get_addon_prefs
from .util import get_real_path
from .util import readOSO, find_it_path, find_local_queue, find_tractor_spool
from .util import get_Files_in_Directory
from . import rman_cycles_convert
from .rfb_logger import rfb_log
from .rman_utils import scene_utils
from .rman_utils.scene_utils import EXCLUDED_OBJECT_TYPES
from .rman_utils import string_utils
from .rman_utils import shadergraph_utils
from .spool import spool_render
from .rman_render import RmanRender
class PRMAN_OT_Renderman_open_stats(bpy.types.Operator):
bl_idname = 'rman.open_stats'
bl_label = "Open Frame Stats"
bl_description = "Open Current Frame stats file"
def execute(self, context):
scene = context.scene
rm = scene.renderman
output_dir = string_utils.expand_string(rm.path_rib_output,
frame=scene.frame_current,
asFilePath=True)
output_dir = os.path.dirname(output_dir)
bpy.ops.wm.url_open(
url="file://" + os.path.join(output_dir, 'stats.%04d.xml' % scene.frame_current))
return {'FINISHED'}
class PRMAN_OT_Renderman_start_it(bpy.types.Operator):
bl_idname = 'rman.start_it'
bl_label = "Start IT"
bl_description = "Start RenderMan's IT"
def execute(self, context):
scene = context.scene
rm = scene.renderman
it_path = find_it_path()
if not it_path:
self.report({"ERROR"},
"Could not find 'it'.")
else:
environ = os.environ.copy()
subprocess.Popen([it_path], env=environ, shell=True)
return {'FINISHED'}
class PRMAN_OT_Renderman_open_last_RIB(bpy.types.Operator):
bl_idname = 'rman.open_rib'
bl_label = "Open Last RIB Scene file."
bl_description = "Opens the last generated Scene.rib file in the system default text editor"
def invoke(self, context, event=None):
"""
rm = context.scene.renderman
rpass = RPass(context.scene, interactive=False)
path = rpass.paths['rib_output']
if not rm.editor_override:
try:
webbrowser.open(path)
except Exception:
debug('error', "File not available!")
else:
command = rm.editor_override + " " + path
try:
os.system(command)
except Exception:
debug(
'error', "File or text editor not available. (Check and make sure text editor is in system path.)")
"""
return {'FINISHED'}
class RENDERMAN_OT_add_remove_output(bpy.types.Operator):
bl_idname = "renderman.add_remove_output"
bl_label = "Add or remove channel from output"
info_string: StringProperty()
def execute(self, context):
self.report({'INFO'}, self.info_string)
return {'FINISHED'}
class SHADING_OT_convert_all_renderman_nodetree(bpy.types.Operator):
''''''
bl_idname = "shading.convert_cycles_stuff"
bl_label = "Convert All Cycles to RenderMan"
bl_description = "Convert all nodetrees to RenderMan"
def execute(self, context):
for mat in bpy.data.materials:
mat.use_nodes = True
nt = mat.node_tree
if shadergraph_utils.is_renderman_nodetree(mat):
continue
output = nt.nodes.new('RendermanOutputNode')
try:
if not rman_cycles_convert.convert_cycles_nodetree(mat, output):
default = nt.nodes.new('PxrSurfaceBxdfNode')
default.location = output.location
default.location[0] -= 300
nt.links.new(default.outputs[0], output.inputs[0])
except Exception as e:
self.report({'ERROR'}, "Error converting " + mat.name)
#self.report({'ERROR'}, str(e))
# uncomment to debug conversion
import traceback
traceback.print_exc()
for light in bpy.data.lights:
if light.renderman.use_renderman_node:
continue
light_type = light.type
light.renderman.light_primary_visibility = False
if light_type == 'SUN':
light.renderman.renderman_type = 'DIST'
elif light_type == 'HEMI':
light.renderman.renderman_type = 'ENV'
light.renderman.light_primary_visibility = True
else:
light.renderman.renderman_type = light_type
if light_type == 'AREA':
light.shape = 'RECTANGLE'
light.size = 1.0
light.size_y = 1.0
#light.renderman.primary_visibility = not light.use_nodes
light.renderman.use_renderman_node = True
# convert cycles vis settings
for ob in context.scene.objects:
if not ob.cycles_visibility.camera:
ob.renderman.visibility_camera = False
if not ob.cycles_visibility.diffuse or not ob.cycles_visibility.glossy:
ob.renderman.visibility_trace_indirect = False
if not ob.cycles_visibility.transmission:
ob.renderman.visibility_trace_transmission = False
return {'FINISHED'}
class SHADING_OT_add_renderman_nodetree(bpy.types.Operator):
''''''
bl_idname = "shading.add_renderman_nodetree"
bl_label = "Add RenderMan Nodetree"
bl_description = "Add a RenderMan shader node tree linked to this material"
idtype: StringProperty(name="ID Type", default="material")
bxdf_name: StringProperty(name="Bxdf Name", default="PxrSurface")
def execute(self, context):
idtype = self.properties.idtype
if idtype == 'node_editor':
idblock = context.space_data.id
idtype = 'material'
else:
context_data = {'material': context.material,
'light': context.light, 'world': context.scene.world}
idblock = context_data[idtype]
# nt = bpy.data.node_groups.new(idblock.name,
# type='RendermanPatternGraph')
#nt.use_fake_user = True
idblock.use_nodes = True
nt = idblock.node_tree
if idtype == 'material':
output = nt.nodes.new('RendermanOutputNode')
if context.material.grease_pencil:
shadergraph_utils.convert_grease_pencil_mat(context.material, nt, output)
elif not rman_cycles_convert.convert_cycles_nodetree(idblock, output):
default = nt.nodes.new('%sBxdfNode' %
self.properties.bxdf_name)
default.location = output.location
default.location[0] -= 300
nt.links.new(default.outputs[0], output.inputs[0])
if idblock.renderman.copy_color_params:
default.diffuseColor = idblock.diffuse_color
default.diffuseGain = idblock.diffuse_intensity
default.enablePrimarySpecular = True
default.specularFaceColor = idblock.specular_color
elif idtype == 'light':
light_type = idblock.type
if light_type == 'SUN':
context.light.renderman.renderman_type = 'DIST'
elif light_type == 'HEMI':
context.light.renderman.renderman_type = 'ENV'
else:
context.light.renderman.renderman_type = light_type
if light_type == 'AREA':
context.light.shape = 'RECTANGLE'
context.light.size = 1.0
context.light.size_y = 1.0
idblock.renderman.use_renderman_node = True
else:
idblock.renderman.renderman_type = "ENV"
idblock.renderman.use_renderman_node = True
# light_type = idblock.type
# light_shader = 'PxrStdAreaLightLightNode'
# if light_type == 'SUN':
# context.light.renderman.type=
# light_shader = 'PxrStdEnvDayLightLightNode'
# elif light_type == 'HEMI':
# light_shader = 'PxrStdEnvMapLightLightNode'
# elif light_type == 'AREA' or light_type == 'POINT':
# idblock.type = "AREA"
# context.light.size = 1.0
# context.light.size_y = 1.0
# else:
# idblock.type = "AREA"
# output = nt.nodes.new('RendermanOutputNode')
# default = nt.nodes.new(light_shader)
# default.location = output.location
# default.location[0] -= 300
# nt.links.new(default.outputs[0], output.inputs[1])
return {'FINISHED'}
######################
# OSL Operators
######################
class PRMAN_OT_refresh_osl_shader(bpy.types.Operator):
bl_idname = "node.refresh_osl_shader"
bl_label = "Refresh OSL Node"
bl_description = "Refreshes the OSL node This takes a second!!"
def invoke(self, context, event):
context.node.RefreshNodes(context)
return {'FINISHED'}
class PRMAN_OT_RendermanBake(bpy.types.Operator):
bl_idname = "renderman.bake"
bl_label = "Baking"
bl_description = "Bake pattern nodes to texture"
def execute(self, context):
scene = context.scene
rman_render = RmanRender.get_rman_render()
if not rman_render.rman_interactive_running:
scene.renderman.hider_type = 'BAKE'
bpy.ops.render.render()
scene.renderman.hider_type = 'RAYTRACE'
else:
self.report({"ERROR"}, "Viewport rendering is on.")
return {'FINISHED'}
class PRMAN_OT_ExternalRender(bpy.types.Operator):
''''''
bl_idname = "renderman.external_render"
bl_label = "External Render"
bl_description = "Launch and external render outside Blender"
rpass = None
is_running = False
def execute(self, context):
scene = context.scene
rman_render = RmanRender.get_rman_render()
if not rman_render.rman_interactive_running:
scene.renderman.enable_external_rendering = True
bpy.ops.render.render()
scene.renderman.enable_external_rendering = False
else:
self.report({"ERROR"}, "Viewport rendering is on.")
return {'FINISHED'}
class PRMAN_OT_StartInteractive(bpy.types.Operator):
''''''
bl_idname = "lighting.start_interactive"
bl_label = "Start Interactive Rendering"
bl_description = "Start Interactive Rendering"
rpass = None
is_running = False
def invoke(self, context, event=None):
for window in bpy.context.window_manager.windows:
for area in window.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
if space.shading.type != 'RENDERED':
space.shading.type = 'RENDERED'
return {'FINISHED'}
class PRMAN_OT_StoptInteractive(bpy.types.Operator):
''''''
bl_idname = "lighting.stop_interactive"
bl_label = "Stop Interactive Rendering"
bl_description = "Stop Interactive Rendering"
rpass = None
is_running = False
def invoke(self, context, event=None):
for window in bpy.context.window_manager.windows:
for area in window.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
if space.shading.type == 'RENDERED':
space.shading.type = 'SOLID'
return {'FINISHED'}
######################
# Export RIB Operators
######################
class PRMAN_OT_ExportRIBObject(bpy.types.Operator):
bl_idname = "export.export_rib_archive"
bl_label = "Export Object as RIB Archive."
bl_description = "Export single object as a RIB archive for use in other blend files or for other uses"
export_mat: BoolProperty(
name="Export Material",
description="Do you want to export the material?",
default=True)
export_all_frames: BoolProperty(
name="Export All Frames",
description="Export entire animation time frame",
default=False)
filepath: bpy.props.StringProperty(
subtype="FILE_PATH")
filename: bpy.props.StringProperty(
subtype="FILE_NAME",
default="")
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
ob = context.active_object
if ob:
export_path = self.filepath
export_range = self.export_all_frames
export_mats = self.export_mat
rman_render = RmanRender.get_rman_render()
if not rman_render.rman_interactive_running:
rman_render.start_export_rib_selected(context, export_path, export_materials=export_mats, export_all_frames=export_range)
else:
self.report({"ERROR"}, "Viewport rendering is on.")
else:
rfb_log().error("Nothing selected for RIB export.")
return {'FINISHED'}
def invoke(self, context, event=None):
context.window_manager.fileselect_add(self)
return{'RUNNING_MODAL'}
###########################
# Presets for integrators.
###########################
def quickAddPresets(presetList, pathFromPresetDir, name):
def as_filename(name): # could reuse for other presets
for char in " !@#$%^&*(){}:\";'[]<>,.\\/?":
name = name.replace(char, '_')
return name.strip()
filename = as_filename(name)
target_path = os.path.join("presets", pathFromPresetDir)
target_path = bpy.utils.user_resource('SCRIPTS',
target_path,
create=True)
if not target_path:
self.report({'WARNING'}, "Failed to create presets path")
return {'CANCELLED'}
filepath = os.path.join(target_path, filename) + ".py"
file_preset = open(filepath, 'w')
file_preset.write("import bpy\n")
for item in presetList:
file_preset.write(str(item) + "\n")
file_preset.close()
class PRMAN_OT_AddPresetRendermanRender(AddPresetBase, bpy.types.Operator):
'''Add or remove a RenderMan Sampling Preset'''
bl_idname = "render.renderman_preset_add"
bl_label = "Add RenderMan Preset"
bl_options = {'REGISTER', 'UNDO'}
preset_menu = "PRMAN_MT_presets"
preset_defines = ["scene = bpy.context.scene", ]
preset_values = [
"scene.renderman.pixel_variance",
"scene.renderman.min_samples",
"scene.renderman.max_samples",
"scene.renderman.max_specular_depth",
"scene.renderman.max_diffuse_depth",
"scene.renderman.motion_blur",
"scene.renderman.do_denoise",
]
preset_subdir = os.path.join("renderman", "render")
# Utility class to contain all default presets
# this has the added bonus of not using operators for each preset
class RendermanRenderPresets():
FinalDenoisePreset = [
"rm = bpy.context.scene.renderman",
"rm.pixel_variance = 0.01",
"rm.min_samples = 32",
"rm.max_samples = 256",
"rm.max_specular_depth = 6",
"rm.max_diffuse_depth = 2",
"rm.motion_blur = True",
"rm.do_denoise = True",
"rm.PxrPathTracer_settings.maxPathLength = 10", ]
FinalHighPreset = [
"rm = bpy.context.scene.renderman",
"rm.pixel_variance = 0.0025",
"rm.min_samples = 64",
"rm.max_samples = 1024",
"rm.max_specular_depth = 6",
"rm.max_diffuse_depth = 3",
"rm.motion_blur = True",
"rm.do_denoise = False",
"rm.PxrPathTracer_settings.maxPathLength = 10", ]
FinalPreset = [
"rm = bpy.context.scene.renderman",
"rm.pixel_variance = 0.005",
"rm.min_samples = 32",
"rm.max_samples = 512",
"rm.max_specular_depth = 6",
"rm.max_diffuse_depth = 2",
"rm.motion_blur = True",
"rm.do_denoise = False",
"rm.PxrPathTracer_settings.maxPathLength = 10", ]
MidPreset = [
"rm = bpy.context.scene.renderman",
"rm.pixel_variance = 0.05",
"rm.min_samples = 0",
"rm.max_samples = 64",
"rm.max_specular_depth = 6",
"rm.max_diffuse_depth = 2",
"rm.motion_blur = True",
"rm.do_denoise = False",
"rm.PxrPathTracer_settings.maxPathLength = 10", ]
PreviewPreset = [
"rm = bpy.context.scene.renderman",
"rm.pixel_variance = 0.1",
"rm.min_samples = 0",
"rm.max_samples = 16",
"rm.max_specular_depth = 2",
"rm.max_diffuse_depth = 1",
"rm.motion_blur = False",
"rm.do_denoise = False",
"rm.PxrPathTracer_settings.maxPathLength = 5", ]
TractorLocalQueuePreset = [
"rm = bpy.context.scene.renderman",
"rm.pixel_variance = 0.01",
"rm.min_samples = 24",
"rm.max_samples = 124",
"rm.max_specular_depth = 6",
"rm.max_diffuse_depth = 2",
"rm.motion_blur = True",
"rm.PxrPathTracer_settings.maxPathLength = 10",
"rm.enable_external_rendering = True",
"rm.external_action = \'spool\'", ]
class PRMAN_MT_PresetsMenu(bpy.types.Menu):
bl_label = "RenderMan Presets"
bl_idname = "PRMAN_MT_presets"
preset_subdir = os.path.join("renderman", "render")
preset_operator = "script.execute_preset"
draw = bpy.types.Menu.draw_preset
#################
# Sample scenes menu.
#################
# Watch out for global list!!
# Its name should be too long to be accedenty called but you never know.
blenderAddonPaths = addon_utils.paths()
rendermanExampleFilesList = []
names = []
for path in blenderAddonPaths:
basePath = os.path.join(path, "RenderManForBlender", "examples")
exists = os.path.exists(basePath)
if exists:
names = get_Files_in_Directory(basePath)
for name in names:
class PRMAN_OT_examplesRenderman(bpy.types.Operator):
bl_idname = ("rendermanexamples." + name.lower())
bl_label = name
bl_description = name
def invoke(self, context, event):
sucess = self.loadFile(self, self.bl_label)
if not sucess:
self.report({'ERROR'}, "Example Does Not Exist!")
return {'FINISHED'}
def loadFile(self, context, exampleName):
blenderAddonPaths = addon_utils.paths()
for path in blenderAddonPaths:
basePath = os.path.join(path, "RenderManForBlender", "examples")
exists = os.path.exists(basePath)
if exists:
examplePath = os.path.join(
basePath, exampleName, exampleName + ".blend")
if(os.path.exists(examplePath)):
bpy.ops.wm.open_mainfile(filepath=examplePath)
return True
else:
return False
rendermanExampleFilesList.append(PRMAN_OT_examplesRenderman)
class PRMAN_MT_LoadSceneMenu(bpy.types.Menu):
bl_label = "RenderMan Examples"
bl_idname = "PRMAN_MT_examples"
def get_operator_failsafe(self, idname):
op = bpy.ops
for attr in idname.split("."):
if attr not in dir(op):
return lambda: None
op = getattr(op, attr)
return op
def draw(self, context):
for operator in rendermanExampleFilesList:
self.layout.operator(operator.bl_idname)
def menu_draw(self, context):
if context.scene.render.engine != "PRMAN_RENDER":
return
icons = load_icons()
examples_menu = icons.get("help")
self.layout.menu("PRMAN_MT_examples", icon_value=examples_menu.icon_id)
# Yuck, this should be built in to blender... Yes it should
class COLLECTION_OT_add_remove(bpy.types.Operator):
bl_label = "Add or Remove Paths"
bl_idname = "collection.add_remove"
action: EnumProperty(
name="Action",
description="Either add or remove properties",
items=[('ADD', 'Add', ''),
('REMOVE', 'Remove', '')],
default='ADD')
context: StringProperty(
name="Context",
description="Name of context member to find renderman pointer in",
default="")
collection: StringProperty(
name="Collection",
description="The collection to manipulate",
default="")
collection_index: StringProperty(
name="Index Property",
description="The property used as a collection index",
default="")
defaultname: StringProperty(
name="Default Name",
description="Default name to give this collection item",
default="")
# BBM addition begin
is_shader_param: BoolProperty(name='Is shader parameter', default=False)
shader_type: StringProperty(
name="shader type",
default='surface')
# BBM addition end
def invoke(self, context, event):
scene = context.scene
# BBM modification
if not self.properties.is_shader_param:
id = string_utils.getattr_recursive(context, self.properties.context)
rm = id.renderman if hasattr(id, 'renderman') else id
else:
if context.active_object.name in bpy.data.lights.keys():
rm = bpy.data.lights[context.active_object.name].renderman
else:
rm = context.active_object.active_material.renderman
id = getattr(rm, '%s_shaders' % self.properties.shader_type)
rm = getattr(id, self.properties.context)
prop_coll = self.properties.collection
coll_idx = self.properties.collection_index
collection = getattr(rm, prop_coll)
index = getattr(rm, coll_idx)
# otherwise just add an empty one
if self.properties.action == 'ADD':
collection.add()
index += 1
setattr(rm, coll_idx, index)
collection[-1].name = self.properties.defaultname
# BBM addition begin
# if coshader array, add the selected coshader
if self.is_shader_param:
coshader_name = getattr(rm, 'bl_hidden_%s_menu' % prop_coll)
collection[-1].name = coshader_name
# BBM addition end
elif self.properties.action == 'REMOVE':
if prop_coll == 'light_groups' and collection[index].name == 'All':
return {'FINISHED'}
elif prop_coll == 'object_groups' and collection[index].name == 'collector':
return {'FINISHED'}
elif prop_coll == 'aov_channels' and not collection[index].custom:
return {'FINISHED'}
else:
collection.remove(index)
setattr(rm, coll_idx, index - 1)
return {'FINISHED'}
class PRMAN_OT_add_renderman_aovs(bpy.types.Operator):
bl_idname = 'renderman.add_renderman_aovs'
bl_label = "Switch to RenderMan Passes"
def execute(self, context):
scene = context.scene
scene.renderman.render_layers.add()
active_layer = context.view_layer
# this sucks. but can't find any other way to refer to render layer
scene.renderman.render_layers[-1].render_layer = active_layer.name
# add the already existing passes
scene = context.scene
rm = scene.renderman
rm_rl = scene.renderman.render_layers[-1]
active_layer = context.view_layer
rl = active_layer
aovs = [
# (name, do?, declare type/name, source)
("color rgba", active_layer.use_pass_combined, "rgba"),
("float z", active_layer.use_pass_z, "z_depth"),
("normal Nn", active_layer.use_pass_normal, "Normal"),
("vector dPdtime", active_layer.use_pass_vector, "Vectors"),
("float u", active_layer.use_pass_uv, "u"),
("float v", active_layer.use_pass_uv, "v"),
("float id", active_layer.use_pass_object_index, "id"),
("color lpe:shadows;C[<.D><.S>]<L.>",
active_layer.use_pass_shadow, "Shadows"),
("color lpe:C<.D><L.>",
active_layer.use_pass_diffuse_direct, "Diffuse"),
("color lpe:(C<RD>[DS]+<L.>)|(C<RD>[DS]*O)",
active_layer.use_pass_diffuse_indirect, "IndirectDiffuse"),
("color lpe:nothruput;noinfinitecheck;noclamp;unoccluded;overwrite;C(U2L)|O",
active_layer.use_pass_diffuse_color, "Albedo"),
("color lpe:C<.S><L.>",
active_layer.use_pass_glossy_direct, "Specular"),
("color lpe:(C<RS>[DS]+<L.>)|(C<RS>[DS]*O)",
active_layer.use_pass_glossy_indirect, "IndirectSpecular"),
("color lpe:(C<TD>[DS]+<L.>)|(C<TD>[DS]*O)",
active_layer.use_pass_subsurface_indirect, "Subsurface"),
("color lpe:emission", active_layer.use_pass_emit, "Emission"),
]
for aov_type, attr, name in aovs:
if attr:
if name == "rgba":
aov_setting = rm_rl.custom_aovs.add()
aov_setting.name = 'beauty'
channel = aov_setting.dspy_channels.add()
channel.name = 'Ci'
channel.channel_name = 'Ci'
channel.channel_def = 'color Ci'
channel = aov_setting.dspy_channels.add()
channel.name = 'a'
channel.channel_name = 'a'
channel.channel_def = 'float a'
else:
aov_setting = rm_rl.custom_aovs.add()
aov_setting.name = name
channel = aov_setting.dspy_channels.add()
channel.name = name
channel.channel_def = aov_type
channel.channel_name = name
return {'FINISHED'}
class PRMAN_OT_add_multilayer_list(bpy.types.Operator):
bl_idname = 'renderman.add_multilayer_list'
bl_label = 'Add multilayer list'
def execute(self, context):
scene = context.scene
scene.renderman.multilayer_lists.add()
active_layer = context.view_layer
scene.renderman.multilayer_lists[-1].render_layer = active_layer.name
return {'FINISHED'}
class PRMAN_OT_add_to_group(bpy.types.Operator):
bl_idname = 'renderman.add_to_group'
bl_label = 'Add Selected to Object Group'
group_index: IntProperty(default=0)
item_type: StringProperty(default='object')
def execute(self, context):
scene = context.scene
group_index = self.properties.group_index
item_type = self.properties.item_type
object_group = scene.renderman.object_groups if item_type == 'object' \
else scene.renderman.light_groups
object_group = object_group[group_index].members
if hasattr(context, 'selected_objects'):
members = object_group.keys()
for ob in context.selected_objects:
if ob.name not in members:
if item_type != 'light' or ob.type == 'LIGHT':
do_add = True
if item_type == 'light' and ob.type == 'LIGHT':
# check if light is already in another group
# can only be in one
for lg in scene.renderman.light_groups:
if ob.name in lg.members.keys():
do_add = False
self.report({'WARNING'}, "Light %s cannot be added to light group %s, already a member of %s" % (
ob.name, scene.renderman.light_groups[group_index].name, lg.name))
if do_add:
ob_in_group = object_group.add()
ob_in_group.name = ob.name
return {'FINISHED'}
class PRMAN_OT_remove_from_group(bpy.types.Operator):
bl_idname = 'renderman.remove_from_group'
bl_label = 'Remove Selected from Object Group'
group_index: IntProperty(default=0)
item_type: StringProperty(default='object')
def execute(self, context):
scene = context.scene
group_index = self.properties.group_index
item_type = self.properties.item_type
object_group = scene.renderman.object_groups if item_type == 'object' \
else scene.renderman.light_groups
object_group = object_group[group_index].members
if hasattr(context, 'selected_objects'):
for ob in context.selected_objects:
if ob.name in object_group.keys():
index = object_group.keys().index(ob.name)
object_group.remove(index)
return {'FINISHED'}
class PRMAN_OT_remove_add_rem_light_link(bpy.types.Operator):
bl_idname = 'renderman.add_rem_light_link'
bl_label = 'Add/Remove Selected from Object Group'
add_remove: StringProperty(default='add')
ll_name: StringProperty(default='')
def execute(self, context):
scene = context.scene
add_remove = self.properties.add_remove
ll_name = self.properties.ll_name
if add_remove == 'add':
ll = scene.renderman.ll.add()
ll.name = ll_name
else:
ll_index = scene.renderman.ll.keys().index(ll_name)
if engine.is_ipr_running():
engine.ipr.remove_light_link(
context, scene.renderman.ll[ll_index])
scene.renderman.ll.remove(ll_index)
return {'FINISHED'}
#################
# Tab #
#################
class PRMAN_OT_Add_Subdiv_Sheme(bpy.types.Operator):
bl_idname = "object.add_subdiv_sheme"
bl_label = "Add Subdiv Sheme"
bl_description = ""
bl_options = {"REGISTER"}
def execute(self, context):
bpy.context.object.renderman.primitive = 'SUBDIVISION_MESH'
return {"FINISHED"}
class PRMAN_OT_RM_Add_Area(bpy.types.Operator):
bl_idname = "object.mr_add_area"
bl_label = "Add RenderMan Area"
bl_description = ""
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.ops.object.light_add(type='AREA')
bpy.ops.shading.add_renderman_nodetree(
{'material': None, 'light': bpy.context.active_object.data}, idtype='light')
return {"FINISHED"}
class PRMAN_OT_RM_Add_LightFilter(bpy.types.Operator):
bl_idname = "object.mr_add_light_filter"
bl_label = "Add RenderMan Light Filter"
bl_description = ""
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.ops.object.light_add(type='POINT')
light = bpy.context.active_object.data
bpy.ops.shading.add_renderman_nodetree(
{'material': None, 'light': light}, idtype='light')
light.renderman.renderman_type = 'FILTER'
return {"FINISHED"}
class PRMAN_OT_RM_Add_Hemi(bpy.types.Operator):
bl_idname = "object.mr_add_hemi"
bl_label = "Add RenderMan Hemi"
bl_description = ""
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.ops.object.light_add(type='SUN')
bpy.ops.shading.add_renderman_nodetree(
{'material': None, 'light': bpy.context.active_object.data}, idtype='light')
bpy.context.object.data.renderman.renderman_type = 'ENV'
return {"FINISHED"}
class PRMAN_OT_RM_Add_Sky(bpy.types.Operator):
bl_idname = "object.mr_add_sky"
bl_label = "Add RenderMan Sky"
bl_description = ""
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.ops.object.light_add(type='SUN')
bpy.ops.shading.add_renderman_nodetree(
{'material': None, 'light': bpy.context.active_object.data}, idtype='light')
bpy.context.object.data.renderman.renderman_type = 'SKY'
return {"FINISHED"}
class PRMAN_OT_Add_bxdf(bpy.types.Operator):
bl_idname = "object.add_bxdf"
bl_label = "Add BXDF"
bl_description = ""
bl_options = {"REGISTER", "UNDO"}
def get_type_items(self, context):
items = [
("PxrSurface", "PxrSurface",
'PxrSurface Uber shader. For most hard surfaces'),
("PxrLayerSurface", "PxrLayerSurface",
"PxrLayerSurface, creates a surface with two Layers"),
("PxrMarschnerHair", "PxrMarschnerHair", "Hair Shader"),
("PxrDisney", "PxrDisney",
"Disney Bxdf, a simple uber shader with no layering"),
("PxrVolume", "PxrVolume", "Volume Shader")
]
# for nodetype in RendermanPatternGraph.nodetypes.values():
# if nodetype.renderman_node_type == 'bxdf':
# items.append((nodetype.bl_label, nodetype.bl_label,
# nodetype.bl_label))
return items
bxdf_name: EnumProperty(items=get_type_items, name="Bxdf Name")
def execute(self, context):
selection = bpy.context.selected_objects if hasattr(
bpy.context, 'selected_objects') else []
#selection = bpy.context.selected_objects
bxdf_name = self.properties.bxdf_name
mat = bpy.data.materials.new(bxdf_name)
mat.use_nodes = True
nt = mat.node_tree
output = nt.nodes.new('RendermanOutputNode')
default = nt.nodes.new('%sBxdfNode' % bxdf_name)
default.location = output.location
default.location[0] -= 300
nt.links.new(default.outputs[0], output.inputs[0])
if bxdf_name == 'PxrLayerSurface':
mixer = nt.nodes.new("PxrLayerMixerPatternNode")
layer1 = nt.nodes.new("PxrLayerPatternNode")
layer2 = nt.nodes.new("PxrLayerPatternNode")
mixer.location = default.location
mixer.location[0] -= 300
layer1.location = mixer.location
layer1.location[0] -= 300
layer1.location[1] += 300
layer2.location = mixer.location
layer2.location[0] -= 300
layer2.location[1] -= 300
nt.links.new(mixer.outputs[0], default.inputs[0])
nt.links.new(layer1.outputs[0], mixer.inputs['baselayer'])
nt.links.new(layer2.outputs[0], mixer.inputs['layer1'])