1import sys
2
3import numpy as np
4
5class OBJECT_TYPE:
6    OT_UNKNOWN, OT_BVH, OT_GEOM, OT_OCTREE, OT_COUNT = range(5)
7
8
9class NODE_TYPE:
10    BV_UNKNOWN, BV_AABB, BV_OBB, BV_RSS, BV_kIOS, BV_OBBRSS, BV_KDOP16, BV_KDOP18, BV_KDOP24, \
11    GEOM_BOX, GEOM_SPHERE, GEOM_ELLIPSOID, GEOM_CAPSULE, GEOM_CONE, GEOM_CYLINDER, GEOM_CONVEX, \
12    GEOM_PLANE, GEOM_HALFSPACE, GEOM_TRIANGLE, GEOM_OCTREE, NODE_COUNT = range(21)
13
14
15class CCDMotionType:
16    CCDM_TRANS, CCDM_LINEAR, CCDM_SCREW, CCDM_SPLINE = range(4)
17
18
19class CCDSolverType:
20    CCDC_NAIVE, CCDC_CONSERVATIVE_ADVANCEMENT, CCDC_RAY_SHOOTING, CCDC_POLYNOMIAL_SOLVER = range(4)
21
22
23class GJKSolverType:
24    GST_LIBCCD, GST_INDEP = range(2)
25
26class Contact:
27    def __init__(self):
28        self.o1 = None
29        self.o2 = None
30        self.b1 = 0
31        self.b2 = 0
32        self.normal = np.array([0.0, 0.0, 0.0])
33        self.pos = np.array([0.0, 0.0, 0.0])
34        self.penetration_depth = 0.0
35
36class CostSource:
37    def __init__(self):
38        self.aabb_min = np.array([0.0, 0.0, 0.0])
39        self.aabb_max = np.array([0.0, 0.0, 0.0])
40        self.cost_density = 0.0
41        self.total_cost = 0.0
42
43class CollisionRequest:
44    def __init__(self,
45                 num_max_contacts=1,
46                 enable_contact=False,
47                 num_max_cost_sources=1,
48                 enable_cost=False,
49                 use_approximate_cost=True,
50                 gjk_solver_type=GJKSolverType.GST_LIBCCD):
51        self.num_max_contacts = num_max_contacts
52        self.enable_contact = enable_contact
53        self.num_max_cost_sources = num_max_cost_sources
54        self.enable_cost = enable_cost
55        self.use_approximate_cost = use_approximate_cost
56        self.gjk_solver_type = gjk_solver_type
57
58class CollisionResult:
59    def __init__(self, is_collision=False):
60        self.is_collision = False
61        self.contacts = []
62        self.cost_sources = []
63
64class ContinuousCollisionRequest:
65    def __init__(self,
66                 num_max_iterations=10,
67                 toc_err=0.0001,
68                 ccd_motion_type=CCDMotionType.CCDM_TRANS,
69                 gjk_solver_type=GJKSolverType.GST_LIBCCD,
70                 ccd_solver_type=CCDSolverType.CCDC_CONSERVATIVE_ADVANCEMENT):
71        self.num_max_iterations = num_max_iterations
72        self.toc_err = toc_err
73        self.ccd_motion_type = ccd_motion_type
74        self.gjk_solver_type = gjk_solver_type
75        self.ccd_solver_type = ccd_solver_type
76
77class ContinuousCollisionResult:
78    def __init__(self, is_collide=False, time_of_contact=1.0):
79        self.is_collide = is_collide
80        self.time_of_contact = time_of_contact
81
82class DistanceRequest:
83    def __init__(self,
84                 enable_nearest_points=False,
85                 gjk_solver_type=GJKSolverType.GST_LIBCCD):
86        self.enable_nearest_points = enable_nearest_points
87        self.gjk_solver_type = gjk_solver_type
88
89class DistanceResult:
90    def __init__(self, min_distance_=sys.float_info.max):
91        self.min_distance = min_distance_
92        self.nearest_points = [None, None]
93        self.o1 = None
94        self.o2 = None
95        self.b1 = -1
96        self.b2 = -1
97
98class CollisionData:
99    def __init__(self, request=None, result=None):
100        if request is None:
101            request = CollisionRequest()
102        if result is None:
103            result = CollisionResult()
104        self.request = request
105        self.result = result
106        self.done = False
107
108class DistanceData:
109    def __init__(self, request=None, result=None):
110        if request is None:
111            request = DistanceRequest()
112        if result is None:
113            result = DistanceResult()
114        self.request = request
115        self.result = result
116        self.done = False
117
118