-
Notifications
You must be signed in to change notification settings - Fork 0
/
properties.py
75 lines (50 loc) · 2.2 KB
/
properties.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
import bpy
from bpy.types import Scene, PropertyGroup
from bpy.props import (
PointerProperty, BoolProperty, EnumProperty,
StringProperty, CollectionProperty, FloatProperty
)
from .constants import MEMBERS_KEY
# -------------------------------------------------------------------
# A property group can have custom methods attached to it for a more
# convenient access. Members 'sample_count', 'accumulated' and 'accumulated_sq'
# are what is stored in .blend files but average() is used for display in panels
# and add_sample() in operators. A property group can hence contain logic.
# TODO : use the default bpy.props.FloatVectorProperty
class FloatVectorProperty(PropertyGroup):
x: FloatProperty()
y: FloatProperty()
z: FloatProperty()
def get(self) -> tuple:
return (self.x, self.y, self.z)
def set(self, value: tuple):
self.x = value[0]
self.y = value[1]
self.z = value[2]
class MemberProperty(PropertyGroup):
# member_type: EnumProperty(name="Member", items=MEMBERS_KEY) # Instantiated by default
points_cloud: CollectionProperty(type=FloatVectorProperty)
# -------------------------------------------------------------------
class SelectionStateProperty(PropertyGroup):
is_active: BoolProperty(name="Is User Selection State", default=False)
selection_member_type: EnumProperty(name="Selection Member", items=MEMBERS_KEY)
def reset(self):
self.is_active = False
# -------------------------------------------------------------------
classes = (
FloatVectorProperty, MemberProperty, SelectionStateProperty,
)
register_cls, unregister_cls = bpy.utils.register_classes_factory(classes)
def register():
register_cls()
# Add properties to all scenes
Scene.active_member_type = EnumProperty(name="Member", items=MEMBERS_KEY)
Scene.active_mesh = StringProperty(name="Target") # Normally is a Human model
Scene.selected_members = CollectionProperty(name="Members", type=MemberProperty)
Scene.selection_state = PointerProperty(type=SelectionStateProperty)
def unregister():
unregister_cls()
del Scene.active_member_type
del Scene.active_mesh
del Scene.selected_members
del Scene.selection_state