3
3
import sys
4
4
import ctypes
5
5
6
+
6
7
class PhysicsDataType (enum .IntEnum ):
7
8
NONE = 0
8
9
CONVEX_MESH = 1
@@ -11,12 +12,14 @@ class PhysicsDataType(enum.IntEnum):
11
12
PRIMITIVE = 4
12
13
CONVEX_MESH_AND_PRIMITIVE = 5
13
14
TRIANGLE_MESH_AND_PRIMITIVE = 6
14
-
15
+
16
+
15
17
class PhysicsCollisionType (enum .IntEnum ):
16
18
NONE = 0
17
19
STATIC = 1
18
20
RIGIDBODY = 2
19
21
22
+
20
23
class PhysicsCollisionLayerType (enum .IntEnum ):
21
24
COLLIDE_WITH_ALL = 0
22
25
STATIC_COLLIDABLES_ONLY = 1
@@ -50,66 +53,126 @@ class PhysicsCollisionLayerType(enum.IntEnum):
50
53
AI_VISION_BLOCKER_AMBIENT_ONLY = 29
51
54
UNUSED_LAST = 30
52
55
56
+
53
57
class PhysicsCollisionPrimitiveType (enum .IntEnum ):
54
58
BOX = 0
55
59
CAPSULE = 1
56
60
SPHERE = 2
57
61
62
+
58
63
class PhysicsCollisionSettings (ctypes .Structure ):
59
64
_fields_ = [
60
65
("data_type" , ctypes .c_uint32 ),
61
66
("collider_type" , ctypes .c_uint32 ),
62
67
]
63
68
69
+
64
70
class Physics :
65
71
def __init__ (self ):
66
72
self .data_type = PhysicsDataType .NONE
67
73
self .collision_type = PhysicsCollisionType .NONE
68
- if not os .environ ['PATH' ].startswith (os .path .abspath (os .path .dirname (__file__ ))):
69
- os .environ ['PATH' ] = os .path .abspath (os .path .dirname (__file__ )) + os .pathsep + os .environ ['PATH' ]
70
- self .lib = ctypes .CDLL (os .path .abspath (os .path .join (os .path .dirname (__file__ ), "alocgen.dll" )), winmode = 0 )
71
- self .lib .AddConvexMesh .argtypes = (ctypes .c_uint32 , ctypes .POINTER (ctypes .c_float ), ctypes .c_uint32 , ctypes .POINTER (ctypes .c_uint32 ), ctypes .c_uint64 ,)
74
+ if not os .environ ["PATH" ].startswith (
75
+ os .path .abspath (os .path .dirname (__file__ ))
76
+ ):
77
+ os .environ ["PATH" ] = (
78
+ os .path .abspath (os .path .dirname (__file__ ))
79
+ + os .pathsep
80
+ + os .environ ["PATH" ]
81
+ )
82
+ self .lib = ctypes .CDLL (
83
+ os .path .abspath (os .path .join (os .path .dirname (__file__ ), "alocgen.dll" )),
84
+ winmode = 0 ,
85
+ )
86
+ self .lib .AddConvexMesh .argtypes = (
87
+ ctypes .c_uint32 ,
88
+ ctypes .POINTER (ctypes .c_float ),
89
+ ctypes .c_uint32 ,
90
+ ctypes .POINTER (ctypes .c_uint32 ),
91
+ ctypes .c_uint64 ,
92
+ )
72
93
self .lib .AddConvexMesh .restype = ctypes .c_int
73
- self .lib .AddTriangleMesh .argtypes = (ctypes .c_uint32 , ctypes .POINTER (ctypes .c_float ), ctypes .c_uint32 , ctypes .POINTER (ctypes .c_uint32 ), ctypes .c_uint64 ,)
94
+ self .lib .AddTriangleMesh .argtypes = (
95
+ ctypes .c_uint32 ,
96
+ ctypes .POINTER (ctypes .c_float ),
97
+ ctypes .c_uint32 ,
98
+ ctypes .POINTER (ctypes .c_uint32 ),
99
+ ctypes .c_uint64 ,
100
+ )
74
101
self .lib .AddTriangleMesh .restype = ctypes .c_int
75
- self .lib .AddPrimitiveBox .argtypes = (ctypes .POINTER (ctypes .c_float ), ctypes .c_uint64 , ctypes .POINTER (ctypes .c_float ), ctypes .POINTER (ctypes .c_float ),)
102
+ self .lib .AddPrimitiveBox .argtypes = (
103
+ ctypes .POINTER (ctypes .c_float ),
104
+ ctypes .c_uint64 ,
105
+ ctypes .POINTER (ctypes .c_float ),
106
+ ctypes .POINTER (ctypes .c_float ),
107
+ )
76
108
self .lib .AddPrimitiveBox .restype = ctypes .c_int
77
- self .lib .AddPrimitiveCapsule .argtypes = (ctypes .c_float , ctypes .c_float , ctypes .c_uint64 , ctypes .POINTER (ctypes .c_float ), ctypes .POINTER (ctypes .c_float ),)
109
+ self .lib .AddPrimitiveCapsule .argtypes = (
110
+ ctypes .c_float ,
111
+ ctypes .c_float ,
112
+ ctypes .c_uint64 ,
113
+ ctypes .POINTER (ctypes .c_float ),
114
+ ctypes .POINTER (ctypes .c_float ),
115
+ )
78
116
self .lib .AddPrimitiveCapsule .restype = ctypes .c_int
79
- self .lib .AddPrimitiveSphere .argtypes = (ctypes .c_float , ctypes .c_uint64 , ctypes .POINTER (ctypes .c_float ), ctypes .POINTER (ctypes .c_float ),)
117
+ self .lib .AddPrimitiveSphere .argtypes = (
118
+ ctypes .c_float ,
119
+ ctypes .c_uint64 ,
120
+ ctypes .POINTER (ctypes .c_float ),
121
+ ctypes .POINTER (ctypes .c_float ),
122
+ )
80
123
self .lib .AddPrimitiveSphere .restype = ctypes .c_int
81
- self .lib .SetCollisionSettings .argtypes = (ctypes .POINTER (PhysicsCollisionSettings ),)
124
+ self .lib .SetCollisionSettings .argtypes = (
125
+ ctypes .POINTER (PhysicsCollisionSettings ),
126
+ )
82
127
self .lib .SetCollisionSettings .restype = ctypes .c_int
83
128
self .lib .NewPhysics ()
84
129
85
130
def write (self , filepath ):
86
131
self .lib .Write (filepath )
87
-
132
+
88
133
def set_collision_settings (self , settings ):
89
134
self .lib .SetCollisionSettings (ctypes .byref (settings ))
90
135
91
136
def add_convex_mesh (self , vertices_list , indices_list , collider_layer ):
92
137
vertices = (ctypes .c_float * len (vertices_list ))(* vertices_list )
93
138
indices = (ctypes .c_uint32 * len (indices_list ))(* indices_list )
94
- self .lib .AddConvexMesh (len (vertices_list ), vertices , int (len (indices_list ) / 3 ), indices , collider_layer )
95
-
139
+ self .lib .AddConvexMesh (
140
+ len (vertices_list ),
141
+ vertices ,
142
+ int (len (indices_list ) / 3 ),
143
+ indices ,
144
+ collider_layer ,
145
+ )
146
+
96
147
def add_triangle_mesh (self , vertices_list , indices_list , collider_layer ):
97
148
vertices = (ctypes .c_float * len (vertices_list ))(* vertices_list )
98
149
indices = (ctypes .c_uint32 * len (indices_list ))(* indices_list )
99
- self .lib .AddTriangleMesh (len (vertices_list ), vertices , int (len (indices_list ) / 3 ), indices , collider_layer )
150
+ self .lib .AddTriangleMesh (
151
+ len (vertices_list ),
152
+ vertices ,
153
+ int (len (indices_list ) / 3 ),
154
+ indices ,
155
+ collider_layer ,
156
+ )
100
157
101
- def add_primitive_box (self , half_extents_list , collider_layer , position_list , rotation_list ):
158
+ def add_primitive_box (
159
+ self , half_extents_list , collider_layer , position_list , rotation_list
160
+ ):
102
161
half_extents = (ctypes .c_float * len (half_extents_list ))(* half_extents_list )
103
162
position = (ctypes .c_float * len (position_list ))(* position_list )
104
163
rotation = (ctypes .c_float * len (rotation_list ))(* rotation_list )
105
164
self .lib .AddPrimitiveBox (half_extents , collider_layer , position , rotation )
106
-
107
- def add_primitive_capsule (self , radius , length , collider_layer , position_list , rotation_list ):
165
+
166
+ def add_primitive_capsule (
167
+ self , radius , length , collider_layer , position_list , rotation_list
168
+ ):
108
169
position = (ctypes .c_float * len (position_list ))(* position_list )
109
170
rotation = (ctypes .c_float * len (rotation_list ))(* rotation_list )
110
171
self .lib .AddPrimitiveCapsule (radius , length , collider_layer , position , rotation )
111
-
112
- def add_primitive_sphere (self , radius , collider_layer , position_list , rotation_list ):
172
+
173
+ def add_primitive_sphere (
174
+ self , radius , collider_layer , position_list , rotation_list
175
+ ):
113
176
position = (ctypes .c_float * len (position_list ))(* position_list )
114
177
rotation = (ctypes .c_float * len (rotation_list ))(* rotation_list )
115
- self .lib .AddPrimitiveSphere (radius , collider_layer , position , rotation )
178
+ self .lib .AddPrimitiveSphere (radius , collider_layer , position , rotation )
0 commit comments