-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path__init__.py
177 lines (157 loc) · 6.25 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
# Info displayed in the add-on overview.
bl_info = {
'name': "6D Lightfield Renderer",
'description': "Create different configurations of lightfields for rendering out scenes.",
'author': "De Pauw Stijn, Courteaux Martijn",
'version': (0, 1),
'blender': (2, 80, 0),
'location': "View3D > Tool Shelf > Lightfield || "
"Properties > Data",
'wiki_url': '',
'support': "COMMUNITY",
'category': "Render"
}
# Importing in this init file is a bit weird.
if "bpy" in locals():
print("Force reloading the plugin.")
import importlib
importlib.reload(lightfield)
importlib.reload(lightfield_plane)
importlib.reload(lightfield_cuboid)
importlib.reload(lightfield_cylinder)
importlib.reload(lightfield_sphere)
importlib.reload(gui)
importlib.reload(operators)
importlib.reload(update)
importlib.reload(config)
importlib.reload(utils)
else:
from . import lightfield, \
lightfield_plane, \
lightfield_cuboid, \
lightfield_cylinder, \
lightfield_sphere, \
gui, \
operators, \
update, \
config, \
utils
import bpy
# -------------------------------------------------------------------
# Register & Unregister
# -------------------------------------------------------------------
def make_annotations(cls):
"""Converts class fields to annotations if running with Blender 2.8"""
version = bpy.app.version
if version < (2, 93, 0):
bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
else:
bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, bpy.props._PropertyDeferred)}
if bl_props:
if '__annotations__' not in cls.__dict__:
setattr(cls, '__annotations__', {})
annotations = cls.__dict__['__annotations__']
for k, v in bl_props.items():
annotations[k] = v
delattr(cls, k)
return cls
# All classes to register.
classes = (
lightfield.LightfieldVisual,
lightfield.LightfieldPropertyGroup,
lightfield_plane.LightfieldPlane,
lightfield_cuboid.LightfieldCuboid,
lightfield_cylinder.LightfieldCylinder,
lightfield_sphere.LightfieldSphere,
gui.VIEW3D_MT_lightfield_add,
gui.DATA_PT_lightfield_setup,
gui.DATA_PT_lightfield_camera,
gui.DATA_PT_lightfield_dof,
gui.DATA_PT_lightfield_dof_aperture,
gui.LIGHTFIELD_UL_items,
gui.LIGHTFIELD_PT_list,
gui.LIGHTFIELD_PT_rendering,
gui.LIGHTFIELD_PT_preview,
gui.LIGHTFIELD_PT_output,
#gui.LIGHTFIELD_PT_persistence,
operators.OBJECT_OT_lightfield_add,
operators.LIGHTFIELD_OT_select,
operators.LIGHTFIELD_OT_make_camera_active,
operators.LIGHTFIELD_OT_move,
operators.LIGHTFIELD_OT_delete_override,
operators.LIGHTFIELD_OT_update,
operators.LIGHTFIELD_OT_update_size,
operators.LIGHTFIELD_OT_update_camera,
operators.LIGHTFIELD_OT_update_preview,
operators.LIGHTFIELD_OT_render,
operators.OBJECT_OT_lightfield_delete,
config.EXPORT_OT_lightfield_config,
config.EXPORT_OT_lightfield_config_append,
)
# Handler for keeping lightfield list in sync with active selection.
@bpy.app.handlers.persistent
def load_handler(temp):
active_object = bpy.types.LayerObjects, "active"
bpy.msgbus.subscribe_rna(key=active_object,
owner=bpy.types.Scene.lightfield_index,
args=(),
notify=update.notify_active_object)
# Needed for updating the size correctly (no recursion).
@bpy.app.handlers.persistent
def update_depsgraph(scene):
# Get the dependency graph.
depsgraph = bpy.context.evaluated_depsgraph_get()
# Check if there is an object that was updated
if depsgraph.id_type_updated('OBJECT'):
# Check if it was the lightfield
lf = utils.get_active_lightfield(bpy.context)
if (lf is not None) and (
lf.obj_empty.evaluated_get(depsgraph) in [_update.id for _update in depsgraph.updates]):
# Update the lightfield.
bpy.app.handlers.depsgraph_update_post.remove(update_depsgraph)
update.update_size()
bpy.app.handlers.depsgraph_update_post.append(update_depsgraph)
# Register all classes + the collection property for storing lightfields
def register():
# Classes
for cls in classes:
make_annotations(cls)
bpy.utils.register_class(cls)
# Properties
bpy.types.Scene.lightfield = bpy.props.CollectionProperty(type=lightfield.LightfieldPropertyGroup)
bpy.types.Scene.lightfield_index = bpy.props.IntProperty(default=-1,
update=update.update_lightfield_index)
bpy.types.Scene.lightfield_autoselect = bpy.props.BoolProperty(default=True,
description="Automatically select light fields in the Viewport")
bpy.types.Scene.lightfield_dryrun = bpy.props.BoolProperty(default=False,
description="Dry-run the render, producing config and directories without actual renders.")
bpy.types.Scene.lightfield_donotoverwrite = bpy.props.BoolProperty(default=False,
description="Do not render views corresponding existing files.")
# Menus
bpy.types.VIEW3D_MT_add.append(gui.add_lightfield)
# Handlers
# Handler for active object
bpy.app.handlers.load_post.append(load_handler)
# Handler for scaling.
# Don't use for now.
# bpy.app.handlers.depsgraph_update_post.append(update_depsgraph)
# Unregister all classes + the collection property for storing lightfields
# This is done in reverse to 'pop the register stack'.
def unregister():
# Handlers
# Don't use scaling for now
# bpy.app.handlers.depsgraph_update_post.remove(update_depsgraph)
bpy.app.handlers.load_post.remove(load_handler)
# Unsubscribe from all possible subscriptions
bpy.msgbus.clear_by_owner(bpy.types.Scene.lightfield_index)
# Remove items from menu
bpy.types.VIEW3D_MT_add.remove(gui.add_lightfield)
# Remove properties
del bpy.types.Scene.lightfield_index
del bpy.types.Scene.lightfield
del bpy.types.Scene.lightfield_autoselect
del bpy.types.Scene.lightfield_dryrun
del bpy.types.Scene.lightfield_donotoverwrite
# Unregister classes
for cls in reversed(classes):
bpy.utils.unregister_class(cls)