-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.py
58 lines (49 loc) · 1.83 KB
/
utils.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
import bpy
from .lightfield_plane import LightfieldPlane
from .lightfield_cuboid import LightfieldCuboid
from .lightfield_cylinder import LightfieldCylinder
from .lightfield_sphere import LightfieldSphere
# from .lightfield_sphere import LightfieldSphere
def get_active_lightfield(context):
"""
Get the active lightfield object, or None if not active
:return: lightfield/None
"""
obj = bpy.context.active_object
if not obj:
return None
for lightfield in bpy.context.scene.lightfield:
if lightfield.obj_empty == obj:
if lightfield.lf_type == 'PLANE':
lf = (LightfieldPlane)(lightfield)
elif lightfield.lf_type == 'CUBOID':
lf = (LightfieldCuboid)(lightfield)
elif lightfield.lf_type == 'CYLINDER':
lf = (LightfieldCylinder)(lightfield)
elif lightfield.lf_type == 'SPHERE':
lf = (LightfieldSphere)(lightfield)
else:
return None
return lf
return None
def get_lightfield_class(enum_name):
"""Return the lightfield class of the corresponding name."""
if enum_name == 'PLANE':
return LightfieldPlane
elif enum_name == 'CUBOID':
return LightfieldCuboid
elif enum_name == 'CYLINDER':
return LightfieldCylinder
elif enum_name == 'SPHERE':
return LightfieldSphere
else:
raise LookupError()
def get_lightfield_collection():
"""Return the collection containing the lightfields."""
LIGHTFIELD_COLLECTION = 'Lightfields'
if LIGHTFIELD_COLLECTION in bpy.data.collections:
collection = bpy.data.collections[LIGHTFIELD_COLLECTION]
else:
collection = bpy.data.collections.new(LIGHTFIELD_COLLECTION)
bpy.context.scene.collection.children.link(collection)
return collection