-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactor_menu.py
112 lines (71 loc) · 3.29 KB
/
actor_menu.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
##############################################################################
# Imports Order: 3rd Party Imports, Python Built-ins, Custom Modules
##############################################################################
import bpy
from . import save_actor
##############################################################################
# Classes
##############################################################################
classes = [] # Initialize the class array to be registered
class OBJECT_PT_ActorInfoMenu(bpy.types.Panel):
""""""
bl_idname = "OBJECT_PT_ActorInfoMenu"
bl_label = "Actor Info"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Level Editor"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
scene = context.scene
obj = context.active_object
def custom_prop(name, parent=layout):
if bpy.data.objects[bpy.context.object.data.name].get(name) is not None:
parent.prop(
bpy.data.objects[bpy.context.object.data.name], f'["{name}"]'
)
# Only populate the actor info if something is selected and it's an actor
if obj.select_get() and ("Actor Type" in context.active_object.keys()):
layout.prop(context.active_object, "name", text="Actor Name")
etype = layout.row()
etype.enabled = False
custom_prop("Actor Type", etype)
layout.prop(context.active_object, "location", text="Actor Translation")
# This won't display properly unless the object is in quaternion mode, so I force all actors into quat mode when added
layout.prop(
context.active_object, "rotation_quaternion", text="Actor Quaternion"
)
layout.separator()
layout.label(text="Custom Properties")
# Show all of the custom properties
for key, value in context.active_object.items():
if key not in [
"Actor Type",
"Mesh",
"Icon",
"JSON Category",
"JSON Index",
]:
custom_prop(key)
# Provide the option to save the actor as a preset
# layout.operator("wm.save_actor")
# Display if something other than an actor is selected
else:
layout.label(text="Select an actor to see its properties.", icon="ERROR")
layout.separator()
classes.append(OBJECT_PT_ActorInfoMenu) # Add the class to the array
##############################################################################
# Functions
##############################################################################
##############################################################################
# Registration
##############################################################################
def register():
for cls in classes: # Register all the classes
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes): # Unregister all the classes
bpy.utils.unregister_class(cls)
del bpy.types.Scene.actor_properties
# if __name__ == "__main__": # For internal Blender script testing
# register()