forked from prman-pixar/RenderManForBlender
-
Notifications
You must be signed in to change notification settings - Fork 2
/
__init__.py
243 lines (199 loc) · 8.33 KB
/
__init__.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
# ##### 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 bgl
import blf
from . import rman_constants
from .rman_utils import filepath_utils
from .rman_utils import texture_utils
from .rman_utils import prefs_utils
from .rman_utils import string_utils
from .rfb_logger import rfb_log
bl_info = {
"name": "RenderMan For Blender",
"author": "Pixar",
"version": (23, 0, 0),
"blender": (2, 80, 0),
"location": "Info Header, render engine menu",
"description": "RenderMan 23.0 integration",
"warning": "",
"category": "Render"}
class PRManRender(bpy.types.RenderEngine):
bl_idname = 'PRMAN_RENDER'
bl_label = "RenderMan Render"
bl_use_preview = True # Turn off preview renders
bl_use_save_buffers = True
bl_use_shading_nodes = True # We support shading nodes
bl_use_shading_nodes_custom = False
bl_use_eevee_viewport = True # Use Eevee for look dev viewport mode
def __init__(self):
from . import rman_render
self.rman_render = rman_render.RmanRender.get_rman_render()
if self.rman_render.rman_interactive_running:
if self.is_preview:
return
self.rman_render.stop_render()
self.rman_render.bl_engine = self
def __del__(self):
pass
def update(self, data, depsgraph):
pass
def view_update(self, context, depsgraph):
'''
For viewport renders. Blender calls view_update when starting viewport renders
and/or something changes in the scene.
'''
# check if we are already doing a regular render
if self.rman_render.rman_running:
return
# if interactive rendering has not started, start it
if not self.rman_render.rman_interactive_running and self.rman_render.sg_scene is None:
self.rman_render.start_interactive_render(context, depsgraph)
if self.rman_render.rman_interactive_running:
self.rman_render.update_scene(context, depsgraph)
def view_draw(self, context, depsgraph):
'''
For viewport renders. Blender calls view_draw whenever it redraws the 3D viewport.
This is where we check for camera moves and draw pxiels from our
Blender display driver.
'''
if self.rman_render.rman_interactive_running:
self.rman_render.update_view(context, depsgraph)
self._draw_pixels(context, depsgraph)
def render(self, depsgraph):
'''
Main render entry point. Blender calls this when doing final renders or preview renders.
'''
bl_scene = depsgraph.scene_eval
if self.is_preview:
if self.rman_render.rman_interactive_running:
rfb_log().error("Cannot preview render while viewport rendering.")
return
self.rman_render.start_swatch_render(depsgraph)
elif bl_scene.renderman.enable_external_rendering:
self.rman_render.start_external_render(depsgraph)
else:
if not self.rman_render.start_render(depsgraph):
return
def _draw_pixels(self, context, depsgraph):
scene = depsgraph.scene
w = context.region.width
h = context.region.height
# Bind shader that converts from scene linear to display space,
bgl.glEnable(bgl.GL_BLEND)
bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA)
self.bind_display_space_shader(scene)
self.rman_render.draw_pixels()
self.unbind_display_space_shader()
bgl.glDisable(bgl.GL_BLEND)
# Draw text area that RenderMan is running.
if prefs_utils.get_addon_prefs().draw_ipr_text:
pos_x = w / 2 - 100
pos_y = 20
blf.enable(0, blf.SHADOW)
blf.shadow_offset(0, 1, -1)
blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.8)
blf.size(0, 32, 36)
blf.position(0, pos_x, pos_y, 0)
blf.color(0, 1.0, 0.0, 0.0, 1.0)
blf.draw(0, "%s" % ('RenderMan Interactive Mode Running'))
blf.disable(0, blf.SHADOW)
# FIXME: these handler registrations should be moved to individual
# register functions
def add_handlers(scene):
# parse for textures to convert on scene load
if texture_utils.parse_for_textures_load_cb not in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.append(texture_utils.parse_for_textures_load_cb)
# token updater on scene load
if string_utils.update_blender_tokens_cb not in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.append(string_utils.update_blender_tokens_cb)
# token updater on scene save
if string_utils.update_blender_tokens_cb not in bpy.app.handlers.save_post:
bpy.app.handlers.save_post.append(string_utils.update_blender_tokens_cb)
def remove_handlers():
if texture_utils.parse_for_textures_load_cb in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.remove(texture_utils.parse_for_textures_load_cb)
if string_utils.update_blender_tokens_cb in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.remove(string_utils.update_blender_tokens_cb)
if string_utils.update_blender_tokens_cb in bpy.app.handlers.save_post:
bpy.app.handlers.save_post.remove(string_utils.update_blender_tokens_cb)
def set_up_paths():
import os
rmantree = filepath_utils.guess_rmantree()
filepath_utils.set_rmantree(rmantree)
filepath_utils.set_pythonpath(os.path.join(rmantree, 'bin'))
it_dir = os.path.dirname(filepath_utils.find_it_path())
filepath_utils.set_path([os.path.join(rmantree, 'bin'), it_dir])
pythonbindings = os.path.join(rmantree, 'bin', 'pythonbindings')
filepath_utils.set_pythonpath(pythonbindings)
def load_addon():
# if rmantree is ok load the stuff
from . import preferences
if filepath_utils.guess_rmantree():
# else display an error, tell user to correct
# and don't load anything else
set_up_paths()
from . import rman_operators
from . import rman_ui
from . import operators
from . import rman_bl_nodes
from . import rman_properties
from . import rman_config
# need this now rather than at beginning to make
# sure preferences are loaded
rman_operators.register()
rman_config.register()
rman_bl_nodes.register()
operators.register()
rman_ui.register()
rman_properties.register()
add_handlers(None)
else:
rfb_log().error(
"Error loading addon. Correct RMANTREE setting in addon preferences.")
classes = [
PRManRender,
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
from . import presets
presets.register()
from . import preferences
preferences.register()
load_addon()
def unregister():
from . import preferences
remove_handlers()
rman_bl_nodes.unregister()
operators.unregister()
rman_ui.unregister()
rman_properties.unregister()
preferences.unregister()
from . import presets
presets.unregister()
rman_operators.unregister()
for cls in classes:
bpy.utils.unregister_class(cls)