forked from taniwha/io_object_mu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties.py
159 lines (142 loc) · 5.64 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
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
# vim:ts=4:et
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import bpy
from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty
from bpy.props import BoolVectorProperty, CollectionProperty, PointerProperty
from bpy.props import FloatVectorProperty, IntProperty
from mathutils import Vector,Matrix,Quaternion
from .mu import MuEnum
class MuSpringProp(bpy.types.PropertyGroup):
spring = FloatProperty(name = "Spring")
damper = FloatProperty(name = "Damper")
targetPosition = FloatProperty(name = "Target")
class MuFrictionProp(bpy.types.PropertyGroup):
extremumSlip = FloatProperty(name = "Slip")
extremumValue = FloatProperty(name = "Value")
asymptoteSlip = FloatProperty(name = "Slip")
asymptoteValue = FloatProperty(name = "Value")
stiffness = FloatProperty(name = "Stiffness")
dir_map = {
'MU_X':0,
'MU_Y':2, # unity is LHS, blender is RHS
'MU_Z':1, # unity is LHS, blender is RHS
0:'MU_X',
2:'MU_Y', # unity is LHS, blender is RHS
1:'MU_Z', # unity is LHS, blender is RHS
}
dir_items = (
('MU_X', "X", ""),
('MU_Y', "Y", ""),
('MU_Z', "Z", ""),
)
collider_items = (
('MU_COL_NONE', "", ""),
('MU_COL_MESH', "Mesh", ""),
('MU_COL_SPHERE', "Sphere", ""),
('MU_COL_CAPSULE', "Capsule", ""),
('MU_COL_BOX', "Box", ""),
('MU_COL_WHEEL', "Wheel", ""),
)
def SetPropMask(prop, mask):
for i in range(32):
prop[i] = (mask & (1 << i)) and True or False
def GetPropMask(prop):
mask = 0
for i in range(32):
mask |= int(prop[i]) << i;
return mask
class MuProperties(bpy.types.PropertyGroup):
tag = StringProperty(name = "Tag", default="Untagged")
layer = IntProperty(name = "Layer")
collider = EnumProperty(items = collider_items, name = "Collider")
isTrigger = BoolProperty(name = "Trigger")
center = FloatVectorProperty(name = "Center", subtype = 'XYZ')
radius = FloatProperty(name = "Radius")
height = FloatProperty(name = "Height")
direction = EnumProperty(items = dir_items, name = "Direction")
size = FloatVectorProperty(name = "Size", subtype = 'XYZ')
mass = FloatProperty(name = "Mass")
suspensionDistance = FloatProperty(name = "Distance")
suspensionSpring = PointerProperty(type=MuSpringProp, name = "Spring")
forwardFriction = PointerProperty(type=MuFrictionProp, name = "Forward")
sideFriction = PointerProperty(type=MuFrictionProp, name = "Sideways")
cullingMask = BoolVectorProperty(size=32, name = "Mask", subtype = 'LAYER')
class MuPropertiesPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'object'
bl_label = 'Mu Properties'
@classmethod
def poll(cls, context):
return True
def draw(self, context):
layout = self.layout
muprops = context.active_object.muproperties
row = layout.row()
col = row.column()
col.prop(muprops, "tag")
col.prop(muprops, "layer")
if type(context.active_object.data) in [bpy.types.PointLamp,
bpy.types.SunLamp,
bpy.types.SpotLamp,
bpy.types.HemiLamp,
bpy.types.AreaLamp]:
col.prop(muprops, "cullingMask")
class MuColliderPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'object'
bl_label = 'Mu Collider'
@classmethod
def poll(cls, context):
muprops = context.active_object.muproperties
return muprops.collider and muprops.collider != 'MU_COL_NONE'
def draw(self, context):
layout = self.layout
muprops = context.active_object.muproperties
row = layout.row()
col = row.column()
# can't change object types :/ (?)
#col.prop(muprops, "collider")
if muprops.collider == 'MU_COL_MESH':
col.prop(muprops, "isTrigger")
elif muprops.collider == 'MU_COL_SPHERE':
col.prop(muprops, "isTrigger")
col.prop(muprops, "radius")
col.prop(muprops, "center")
elif muprops.collider == 'MU_COL_CAPSULE':
col.prop(muprops, "isTrigger")
col.prop(muprops, "radius")
col.prop(muprops, "height")
col.prop(muprops, "direction")
col.prop(muprops, "center")
elif muprops.collider == 'MU_COL_BOX':
col.prop(muprops, "isTrigger")
col.prop(muprops, "size")
col.prop(muprops, "center")
elif muprops.collider == 'MU_COL_WHEEL':
col.prop(muprops, "isTrigger")
col.prop(muprops, "radius")
col.prop(muprops, "center")
col.prop(muprops, "suspensionDistance")
def register():
bpy.types.Object.muproperties = PointerProperty(type=MuProperties)
def unregister():
pass