-
Notifications
You must be signed in to change notification settings - Fork 47
/
__init__.py
454 lines (377 loc) · 13.6 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
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
""" Initialize eeVR blender plugin """
# pylint: disable=import-error
import os
import time
from datetime import datetime
from math import radians, degrees
if "bpy" in locals():
import importlib
importlib.reload(renderer)
else:
from . import renderer
from .renderer import Renderer
import bpy
from bpy.types import Context, Operator, Panel
bl_info = {
"name": "eeVR",
"description": "Render in different projections using Eevee engine",
"author": "EternalTrail",
"version": (1, 0, 1),
"blender": (3, 6, 0),
"location": "Properties > Render Tab (Available when EEVEE or Workbench)",
"wiki_url": "https://github.com/EternalTrail/eeVR",
"tracker_url": "https://github.com/EternalTrail/eeVR/issues",
"support": "COMMUNITY",
"category": "Render",
}
def has_invalid_condition(self : 'Operator', context : 'Context'):
if context.scene.camera == None:
self.report({'ERROR'}, "eeVR ERROR : Scene camera is not set.")
return True
if context.active_object != None and context.active_object.mode != 'OBJECT':
self.report({'ERROR'}, "eeVR ERROR : Active object's mode is not object mode.")
return True
return False
class RenderImage(Operator):
"""Render out the animation"""
bl_idname = 'eevr.render_image'
bl_label = "Render a single frame"
def execute(self, context):
print("eeVR: execute")
if has_invalid_condition(self, context):
return {'FINISHED'}
renderer = Renderer(context, False)
now = time.time()
try:
renderer.render_and_save()
finally:
renderer.clean_up(context)
print(f"eeVR: {round(time.time() - now, 2)} seconds")
return {'FINISHED'}
class RenderAnimation(Operator):
"""Render out the animation"""
bl_idname = 'eevr.render_animation'
bl_label = "Render the animation"
def __del__(self):
print("eeVR: end")
def modal(self, context, event):
if event.type in {'ESC'}:
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
wm = context.window_manager
wm.event_timer_remove(self.timer)
if context.scene.eeVR.cancel:
self.cancel(context)
return {'CANCELLED'}
if context.scene.frame_current <= self.frame_end:
print(f"eeVR: Rendering frame {context.scene.frame_current}")
now = time.time()
try:
self.renderer.render_and_save()
except Exception as e:
self.clean(context)
raise e
print(f"eeVR: {round(time.time() - now, 2)} seconds")
self.timer = wm.event_timer_add(0.1, window=context.window)
else:
self.clean(context)
return {'FINISHED'}
return {'PASS_THROUGH'}
def execute(self, context):
print("eeVR: execute")
if has_invalid_condition(self, context):
return {'FINISHED'}
context.scene.eeVR.cancel = False
# knowing it's animation, creates folder outside vrrender class, pass folder name to it
start_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
folder_name = f"{os.path.splitext(bpy.path.basename(bpy.data.filepath))[0]} {start_time}/"
path = bpy.path.abspath(context.preferences.filepaths.render_output_directory)
os.makedirs(path+folder_name, exist_ok=True)
self.renderer = Renderer(context, True, folder_name)
self.frame_end = context.scene.frame_end
frame_start = context.scene.frame_start
context.scene.frame_set(frame_start)
wm = context.window_manager
self.timer = wm.event_timer_add(5, window=context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
print("eeVR: cancel")
self.clean(context)
def clean(self, context):
self.renderer.clean_up(context)
context.scene.eeVR.cancel = True
class Cancel(Operator):
"""Render out the animation"""
bl_idname = 'eevr.render_cancel'
bl_label = "Cancel the render"
def execute(self, context):
context.scene.eeVR.cancel = True
return {'FINISHED'}
class RenderPanel(Panel):
"""Render panel for VR rendering"""
bl_idname = "EEVR_PT_render"
bl_label = "eeVR"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "render"
bl_category = "eeVR"
bl_options = {'DEFAULT_CLOSED'}
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_EEVEE_NEXT', 'BLENDER_WORKBENCH'}
@classmethod
def poll(cls, context):
return (context.engine in cls.COMPAT_ENGINES)
def draw(self, context):
props : Properties = context.scene.eeVR
# Draw the buttons for each of the rendering operators
layout = self.layout
col = layout.column()
col.prop(props, 'renderModeEnum')
if props.renderModeEnum == 'DOME':
col.prop(props, 'domeMethodEnum')
col.prop(props, 'fovModeEnum')
if props.fovModeEnum == '180':
col.prop(props, 'HFOV180')
else:
col.prop(props, 'HFOV360')
col.prop(props, 'VFOV')
if props.get_hfov() <= radians(270):
col.prop(props, 'frontFOV')
max_fov = props.get_max_fov()
if props.frontFOV > max_fov:
col.label(icon='ERROR', text=f"clips to {degrees(max_fov):3.0f}°")
col.prop(props, 'stitchMargin')
col.prop(props, 'frontViewResolution')
if props.get_hfov() > props.get_front_fov():
col.prop(props, 'sideViewResolution')
if props.get_vfov() > props.get_front_fov():
col.prop(props, 'topViewResolution')
col.prop(props, 'bottomViewResolution')
if props.get_hfov() > radians(270):
col.prop(props, 'rearViewResolution')
if context.scene.render.use_multiview and props.is_top_bottom(context):
col.prop(props, 'isTopRightEye')
if context.scene.render.use_multiview and props.get_hfov() > radians(180):
col.prop(props, 'appliesParallaxForSideAndBack')
col.label(icon='ERROR', text="eeVR cannot support stereo over 180° fov correctly.")
layout.separator()
col = layout.column()
col.operator(RenderImage.bl_idname, icon="RENDER_STILL", text="Render Image")
col.operator(RenderAnimation.bl_idname, icon="RENDER_ANIMATION", text="Render Animation")
if not props.cancel:
col.operator(Cancel.bl_idname, text="Cancel")
col.label(text=f"Rendering frame {context.scene.frame_current}")
# eeVR's properties
class Properties(bpy.types.PropertyGroup):
renderModeEnum: bpy.props.EnumProperty(
items=[
("EQUI", "Equirectangular", "Renders in equirectangular projection"),
("DOME", "Full Dome", "Renders in full dome projection"),
],
default="EQUI",
name="Mode",
)
domeMethodEnum: bpy.props.EnumProperty(
items=[
("0", "Equidistant (VTA)", "Renders in equidistant dome projection"),
("1", "Hemispherical (VTH)", "Renders in hemispherical dome projection"),
("2", "Equisolid", "Renders in equisolid dome projection"),
("3", "Stereographic", "Renders in Stereographic dome projection"),
],
default="0",
name="Method",
)
fovModeEnum: bpy.props.EnumProperty(
items=[
("180", "180°", "VR 180"),
("360", "360°", "VR 360 (over 180°, not support stereo)"),
("ANY", "Custom FOV", "over 180°, not support stereo"),
],
default="180",
name="VR Format",
)
HFOV360: bpy.props.FloatProperty(
name="Horizontal FOV",
subtype='ANGLE',
precision=0,
step=100,
default=radians(360),
min=radians(1),
max=radians(360),
description="Horizontal Field of view in degrees",
)
HFOV180: bpy.props.FloatProperty(
name="Horizontal FOV",
subtype='ANGLE',
unit='ROTATION',
precision=0,
step=100,
default=radians(180),
min=radians(1),
max=radians(180),
description="Horizontal Field of view in degrees",
)
VFOV: bpy.props.FloatProperty(
name="Vertical FOV",
subtype='ANGLE',
unit='ROTATION',
precision=0,
step=100,
default=radians(180),
min=radians(1),
max=radians(180),
description="Vertical Field of view in degrees",
)
frontFOV: bpy.props.FloatProperty(
name="Front View FOV",
subtype='ANGLE',
unit='ROTATION',
precision=0,
step=100,
default=radians(90),
min=radians(90),
max=radians(160),
description="Front View's Field of view in degrees",
)
stitchMargin: bpy.props.FloatProperty(
name="Stitch Margin",
subtype='ANGLE',
unit='ROTATION',
precision=0,
step=100,
default=radians(5),
min=radians(0),
max=radians(15),
description="Margin for Seam Blending in degrees",
)
frontViewResolution: bpy.props.FloatProperty(
name="Front View Resolution",
subtype='PERCENTAGE',
precision=0,
step=100,
default=90,
min=1,
max=100,
description="Overscan/Reduction Rate for Front View Rendering",
)
sideViewResolution: bpy.props.FloatProperty(
name="Side View Resolution",
subtype='PERCENTAGE',
precision=0,
step=100,
default=90,
min=1,
max=100,
description="Overscan/Reduction Rate for Side View Rendering",
)
topViewResolution: bpy.props.FloatProperty(
name="Top View Resolution",
subtype='PERCENTAGE',
precision=0,
step=100,
default=90,
min=1,
max=100,
description="Overscan/Reduction Rate for Top View Rendering",
)
bottomViewResolution: bpy.props.FloatProperty(
name="Bottom View Resolution",
subtype='PERCENTAGE',
precision=0,
step=100,
default=90,
min=1,
max=100,
description="Overscan/Reduction Rate for Bottom View Rendering",
)
rearViewResolution: bpy.props.FloatProperty(
name="Rear View Resolution",
subtype='PERCENTAGE',
precision=0,
step=100,
default=90,
min=1,
max=100,
description="Overscan/Reduction Rate for Rear View Rendering",
)
appliesParallaxForSideAndBack: bpy.props.BoolProperty(
description="If it is on, it allows for noticeable seams or blending artifacts in side and rear views to introduce collect parallax"\
" at over HFOV 180 rendering. default is false.",
default=False,
name="Apply Parallax for side and rear view",
)
isTopRightEye: bpy.props.BoolProperty(
description="If it is on, right eye image will be placed as top image. default is false.",
default=False,
name="Top is RightEye",
)
trueTopBottom: bpy.props.BoolProperty(
name="TrueTopBottom",
default=False
)
cancel: bpy.props.BoolProperty(
name="Cancel",
default=True
)
@staticmethod
def snap_angle(src: float) -> float:
if abs(src - radians(90)) < 0.000001:
return radians(90)
elif abs(src - radians(180)) < 0.000001:
return radians(180)
elif abs(src - radians(270)) < 0.000001:
return radians(270)
elif abs(src - radians(360)) < 0.000001:
return radians(360)
return src
def get_hfov(self) -> float:
return self.snap_angle(self.HFOV180 if self.fovModeEnum == '180' else self.HFOV360)
def get_vfov(self) -> float:
return self.snap_angle(self.VFOV)
def get_max_fov(self) -> float:
return max(self.get_hfov(), self.get_vfov())
def get_front_fov(self) -> float:
return min(self.snap_angle(self.frontFOV), self.get_max_fov()) if self.get_hfov() <= radians(270) else radians(90)
def is_top_bottom(self, context: Context) -> bool:
if self.cancel:
return context.scene.render.image_settings.stereo_3d_format.display_mode =='TOPBOTTOM'
else:
return self.trueTopBottom
@classmethod
def register(cls):
""" Register eeVR's properties to Blender """
bpy.types.Scene.eeVR = bpy.props.PointerProperty(type=cls)
@classmethod
def unregister(cls):
""" Unregister eeVR's properties from Blender """
del bpy.types.Scene.eeVR
class Preferences(bpy.types.AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__
remain_temporalies: bpy.props.BoolProperty(
name='Remain temporal work files',
description='Temporal rendering images will not be removed.',
default=False
)
temporal_file_format: bpy.props.EnumProperty(
items=[
("PNG", "PNG", "Output image in PNG format."),
("TARGA_RAW", "Targa Raw", "Output image in uncompressed Targa format."),
],
default="TARGA_RAW",
name="Temporal File Format",
)
def draw(self, context):
self.layout.row().prop(self, 'remain_temporalies')
self.layout.row().prop(self, 'temporal_file_format')
# REGISTER
register, unregister = bpy.utils.register_classes_factory((
Properties,
RenderPanel,
RenderImage,
RenderAnimation,
Cancel,
Preferences,
))