nablaengine 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nablaengine/__init__.py +4 -0
- nablaengine/_fixtures/README.md +19 -0
- nablaengine/_fixtures/data/mf_s0.npz +0 -0
- nablaengine/_fixtures/mjlab/LICENSE +27 -0
- nablaengine/_fixtures/mjlab/README.md +113 -0
- nablaengine/_fixtures/mjlab/g1_meta.json +32 -0
- nablaengine/_fixtures/mjlab/g1_train.mjb +0 -0
- nablaengine/_optional.py +30 -0
- nablaengine/_paths.py +38 -0
- nablaengine/actuators/__init__.py +169 -0
- nablaengine/actuators/bam.py +306 -0
- nablaengine/actuators/bam_params/LICENSE +202 -0
- nablaengine/actuators/bam_params/xl330/m6.json +19 -0
- nablaengine/boxbox.py +259 -0
- nablaengine/ccd.py +1122 -0
- nablaengine/checks.py +376 -0
- nablaengine/cuda.py +483 -0
- nablaengine/dist_query.py +628 -0
- nablaengine/dual.py +223 -0
- nablaengine/dyn_query.py +685 -0
- nablaengine/engines.py +114 -0
- nablaengine/envs/__init__.py +24 -0
- nablaengine/envs/brax.py +165 -0
- nablaengine/envs/convert.py +771 -0
- nablaengine/envs/dmc.py +523 -0
- nablaengine/envs/env.py +233 -0
- nablaengine/envs/kin.py +371 -0
- nablaengine/envs/ops.py +134 -0
- nablaengine/envs/rewards.py +57 -0
- nablaengine/fixtures.py +243 -0
- nablaengine/forest_engine/__init__.py +0 -0
- nablaengine/forest_engine/adjoint.py +1726 -0
- nablaengine/forest_engine/adjoint_contact.py +493 -0
- nablaengine/forest_engine/bam_hooks.py +248 -0
- nablaengine/forest_engine/body_params.py +1007 -0
- nablaengine/forest_engine/capacity_diag.py +116 -0
- nablaengine/forest_engine/ccd_coop.py +250 -0
- nablaengine/forest_engine/chol_blk.py +80 -0
- nablaengine/forest_engine/contact_forces.py +142 -0
- nablaengine/forest_engine/contact_vjp.py +462 -0
- nablaengine/forest_engine/convex.py +1331 -0
- nablaengine/forest_engine/cylinder.py +73 -0
- nablaengine/forest_engine/dist_device.py +923 -0
- nablaengine/forest_engine/dyn_device.py +696 -0
- nablaengine/forest_engine/ellipsoid.py +179 -0
- nablaengine/forest_engine/elliptic.py +272 -0
- nablaengine/forest_engine/equality.py +842 -0
- nablaengine/forest_engine/floss.py +148 -0
- nablaengine/forest_engine/foot_offset.py +368 -0
- nablaengine/forest_engine/free_gyro.py +288 -0
- nablaengine/forest_engine/host.py +530 -0
- nablaengine/forest_engine/kdof64.py +127 -0
- nablaengine/forest_engine/kinematics.py +320 -0
- nablaengine/forest_engine/margin.py +167 -0
- nablaengine/forest_engine/margin_convex.py +326 -0
- nablaengine/forest_engine/midphase.py +439 -0
- nablaengine/forest_engine/model_hooks.py +913 -0
- nablaengine/forest_engine/motor_hooks.py +50 -0
- nablaengine/forest_engine/muscle.py +485 -0
- nablaengine/forest_engine/nb128.py +118 -0
- nablaengine/forest_engine/nb64.py +163 -0
- nablaengine/forest_engine/noslip.py +1124 -0
- nablaengine/forest_engine/nv128.py +1944 -0
- nablaengine/forest_engine/object_size.py +283 -0
- nablaengine/forest_engine/replay_guard.py +40 -0
- nablaengine/forest_engine/root_spread.py +126 -0
- nablaengine/forest_engine/solref.py +74 -0
- nablaengine/forest_engine/source.py +1464 -0
- nablaengine/forest_engine/sparse_pattern.py +527 -0
- nablaengine/forest_engine/spatial.py +1045 -0
- nablaengine/forest_engine/step.py +3083 -0
- nablaengine/forest_engine/surrogate.py +498 -0
- nablaengine/forest_engine/tape.py +199 -0
- nablaengine/forest_engine/tendon.py +845 -0
- nablaengine/forest_engine/terrain.py +1059 -0
- nablaengine/forest_engine/world_forces.py +166 -0
- nablaengine/forest_engine/world_params.py +230 -0
- nablaengine/g1_engine/__init__.py +0 -0
- nablaengine/g1_engine/adjoint.py +1661 -0
- nablaengine/g1_engine/adjoint_contact.py +577 -0
- nablaengine/g1_engine/bam_hooks.py +596 -0
- nablaengine/g1_engine/condim4.py +245 -0
- nablaengine/g1_engine/contact_forces.py +500 -0
- nablaengine/g1_engine/cylccd.py +1158 -0
- nablaengine/g1_engine/cylinder.py +216 -0
- nablaengine/g1_engine/elliptic.py +565 -0
- nablaengine/g1_engine/exact_replay.py +61 -0
- nablaengine/g1_engine/host.py +358 -0
- nablaengine/g1_engine/kinematics.py +320 -0
- nablaengine/g1_engine/mesh.py +305 -0
- nablaengine/g1_engine/mesh_tables.py +79 -0
- nablaengine/g1_engine/model_hooks.py +919 -0
- nablaengine/g1_engine/motor_hooks.py +70 -0
- nablaengine/g1_engine/replay_guard.py +55 -0
- nablaengine/g1_engine/source.py +1107 -0
- nablaengine/g1_engine/sphbox.py +93 -0
- nablaengine/g1_engine/step.py +3716 -0
- nablaengine/g1_engine/tape.py +173 -0
- nablaengine/g1_engine/world_params.py +447 -0
- nablaengine/identity.py +401 -0
- nablaengine/jax_ffi.py +2536 -0
- nablaengine/model/__init__.py +1 -0
- nablaengine/model/capability.py +694 -0
- nablaengine/model/fields.py +317 -0
- nablaengine/model/gravcomp.py +64 -0
- nablaengine/model/invweight.py +145 -0
- nablaengine/motor.py +143 -0
- nablaengine/object_geometry.py +609 -0
- nablaengine/params.py +258 -0
- nablaengine/provenance.py +196 -0
- nablaengine/reference/__init__.py +0 -0
- nablaengine/reference/adjoint_groups.py +226 -0
- nablaengine/reference/jax64.py +690 -0
- nablaengine/reference/warp_physics.py +262 -0
- nablaengine/sensors/__init__.py +4 -0
- nablaengine/sensors/cameras.py +285 -0
- nablaengine/sensors/data/LIVOX_MID360_LICENSE +21 -0
- nablaengine/sensors/data/livox_mid360.npz +0 -0
- nablaengine/sensors/g1.py +521 -0
- nablaengine/sensors/jax_rays.py +364 -0
- nablaengine/sensors/optix_rays.py +725 -0
- nablaengine/sensors/raycore.py +630 -0
- nablaengine/sensors/raygrad.py +374 -0
- nablaengine/sensors/raygrad_cuda.py +191 -0
- nablaengine/sensors/robot_mesh.py +273 -0
- nablaengine/sensors/torch_rays.py +275 -0
- nablaengine/terrain.py +424 -0
- nablaengine/torch_ffi.py +1328 -0
- nablaengine/workdir.py +37 -0
- nablaengine-1.0.2.dist-info/METADATA +236 -0
- nablaengine-1.0.2.dist-info/RECORD +136 -0
- nablaengine-1.0.2.dist-info/WHEEL +5 -0
- nablaengine-1.0.2.dist-info/licenses/LICENSE +202 -0
- nablaengine-1.0.2.dist-info/licenses/NOTICE +23 -0
- nablaengine-1.0.2.dist-info/licenses/THIRD_PARTY_NOTICES.md +176 -0
- nablaengine-1.0.2.dist-info/top_level.txt +1 -0
nablaengine/boxbox.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"""MuJoCo Warp's box-box primitive as device code over a scalar type (mujoco_warp/_src/collision_primitive_core.py,
|
|
2
|
+
box_box and _box_box_clip, the same in MuJoCo Warp 3.17 and 4.0; Copyright 2025 The Newton Developers, Apache License
|
|
3
|
+
2.0; itself a port of MuJoCo's mjc_BoxBox): a separating-axis test that prefers face axes on near-ties, then the
|
|
4
|
+
incident face clipped against the reference face (up to 8 contacts) or one edge-edge contact. Its order of operations,
|
|
5
|
+
so that the contacts agree with MuJoCo Warp's up to float rounding."""
|
|
6
|
+
|
|
7
|
+
DEVICE = r"""
|
|
8
|
+
// MuJoCo Warp's box_box (collision_primitive_core.py; nablaengine.boxbox), over a scalar type
|
|
9
|
+
#define BB_SEPEPS 1e-6f // slack on the separation tests, times the box scale
|
|
10
|
+
#define BB_PAREPS 1e-7f // sin^2 below which an edge-cross axis is noise
|
|
11
|
+
#define BB_SGNEPS 1e-5f // axis component below which a support corner is ambiguous
|
|
12
|
+
#define BB_DUPEPS 1e-10f // squared relative radius for clip-vertex deduplication
|
|
13
|
+
#define BB_EDGEBIAS 1e-6f // relative penalty on edge-axis separation on near-ties with the best face axis
|
|
14
|
+
#define BB_MAXVERT 8
|
|
15
|
+
#define BB_MAXVAL 1e10f // mjMAXVAL
|
|
16
|
+
#define BB_MINVAL 1e-15f // mjMINVAL
|
|
17
|
+
|
|
18
|
+
template <class T>
|
|
19
|
+
__device__ __forceinline__ T bb_clamp(T x, float lo, float hi) { return t_fmin(t_fmax(x, lo), hi); }
|
|
20
|
+
|
|
21
|
+
// the polygon (nin vertices) clipped against the half-plane sign * v[coord] <= limit (_box_box_clip; unchanged when
|
|
22
|
+
// every vertex is inside)
|
|
23
|
+
template <class T>
|
|
24
|
+
__device__ int bb_clip(int nin, T (*poly)[3], int coord, float sign, float limit) {
|
|
25
|
+
T d[BB_MAXVERT];
|
|
26
|
+
bool all_inside = true;
|
|
27
|
+
for (int k = 0; k < nin; k++) {
|
|
28
|
+
d[k] = sign * poly[k][coord] - limit;
|
|
29
|
+
if (!(d[k] <= 0.f)) all_inside = false;
|
|
30
|
+
}
|
|
31
|
+
if (all_inside) return nin;
|
|
32
|
+
T out[BB_MAXVERT][3];
|
|
33
|
+
int nout = 0;
|
|
34
|
+
for (int k = 0; k < nin; k++) {
|
|
35
|
+
const int k1 = k + 1 == nin ? 0 : k + 1;
|
|
36
|
+
const T dp = d[k], dq = d[k1];
|
|
37
|
+
if (dp <= 0.f && nout < BB_MAXVERT) {
|
|
38
|
+
for (int c = 0; c < 3; c++) out[nout][c] = poly[k][c];
|
|
39
|
+
nout++;
|
|
40
|
+
}
|
|
41
|
+
if (((dp < 0.f && dq > 0.f) || (dp > 0.f && dq < 0.f)) && nout < BB_MAXVERT) {
|
|
42
|
+
const T t = dp / (dp - dq);
|
|
43
|
+
for (int c = 0; c < 3; c++) out[nout][c] = poly[k][c] + t * (poly[k1][c] - poly[k][c]);
|
|
44
|
+
nout++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (int k = 0; k < nout; k++)
|
|
48
|
+
for (int c = 0; c < 3; c++) poly[k][c] = out[k][c];
|
|
49
|
+
return nout;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
template <class T>
|
|
53
|
+
__device__ int bb_box_box_t(const T* p1, const T* R1, const float* s1, const T* p2, const T* R2, const float* s2,
|
|
54
|
+
float margin, T* cdist, T (*cpos)[3], T* cnrm) {
|
|
55
|
+
// rot: box 2's axes in box 1's frame (columns); pos21: box 2's center in box 1's frame; pos12: box 1's in box 2's
|
|
56
|
+
T d21[3], d12[3], pos21[3], pos12[3], rot[3][3], rabs[3][3];
|
|
57
|
+
for (int k = 0; k < 3; k++) { d21[k] = p2[k] - p1[k]; d12[k] = p1[k] - p2[k]; }
|
|
58
|
+
for (int i = 0; i < 3; i++) {
|
|
59
|
+
pos21[i] = R1[i] * d21[0] + R1[3 + i] * d21[1] + R1[6 + i] * d21[2];
|
|
60
|
+
pos12[i] = R2[i] * d12[0] + R2[3 + i] * d12[1] + R2[6 + i] * d12[2];
|
|
61
|
+
}
|
|
62
|
+
for (int i = 0; i < 3; i++)
|
|
63
|
+
for (int j = 0; j < 3; j++) {
|
|
64
|
+
rot[i][j] = R1[i] * R2[j] + R1[3 + i] * R2[3 + j] + R1[6 + i] * R2[6 + j];
|
|
65
|
+
rabs[i][j] = t_fabs(rot[i][j]);
|
|
66
|
+
}
|
|
67
|
+
// stage 1: the separating-axis test (with rounding slack)
|
|
68
|
+
const float septol = margin + BB_SEPEPS * (s1[0] + s1[1] + s1[2] + s2[0] + s2[1] + s2[2]);
|
|
69
|
+
T sep_best = T(-BB_MAXVAL);
|
|
70
|
+
int code = -1;
|
|
71
|
+
for (int i = 0; i < 3; i++) { // face axes of box 1
|
|
72
|
+
T radius2 = rabs[i][0] * s2[0] + rabs[i][1] * s2[1] + rabs[i][2] * s2[2];
|
|
73
|
+
T sep = t_fabs(pos21[i]) - s1[i] - radius2;
|
|
74
|
+
if (sep > septol) return 0;
|
|
75
|
+
if (sep > sep_best) { sep_best = sep; code = i; }
|
|
76
|
+
}
|
|
77
|
+
for (int j = 0; j < 3; j++) { // face axes of box 2
|
|
78
|
+
T radius1 = rabs[0][j] * s1[0] + rabs[1][j] * s1[1] + rabs[2][j] * s1[2];
|
|
79
|
+
T sep = t_fabs(pos12[j]) - s2[j] - radius1;
|
|
80
|
+
if (sep > septol) return 0;
|
|
81
|
+
if (sep > sep_best) { sep_best = sep; code = 3 + j; }
|
|
82
|
+
}
|
|
83
|
+
const T sep_face = sep_best;
|
|
84
|
+
const int code_face = code;
|
|
85
|
+
for (int i = 0; i < 3; i++) // edge-cross axes: axis i of box 1 x axis j of box 2
|
|
86
|
+
for (int j = 0; j < 3; j++) {
|
|
87
|
+
const int i1 = (i + 1) % 3, i2 = (i + 2) % 3;
|
|
88
|
+
T ax1 = -rot[i2][j], ax2 = rot[i1][j];
|
|
89
|
+
T norm2 = ax1 * ax1 + ax2 * ax2;
|
|
90
|
+
if (norm2 < BB_PAREPS) continue;
|
|
91
|
+
T inv = 1.f / t_sqrt(norm2);
|
|
92
|
+
ax1 = ax1 * inv;
|
|
93
|
+
ax2 = ax2 * inv;
|
|
94
|
+
T radius1 = s1[i1] * t_fabs(ax1) + s1[i2] * t_fabs(ax2);
|
|
95
|
+
const int j1 = (j + 1) % 3, j2 = (j + 2) % 3;
|
|
96
|
+
T a21 = ax1 * rot[i1][j1] + ax2 * rot[i2][j1];
|
|
97
|
+
T a22 = ax1 * rot[i1][j2] + ax2 * rot[i2][j2];
|
|
98
|
+
T radius2 = s2[j1] * t_fabs(a21) + s2[j2] * t_fabs(a22);
|
|
99
|
+
T sep = t_fabs(ax1 * pos21[i1] + ax2 * pos21[i2]) - radius1 - radius2;
|
|
100
|
+
if (sep > septol) return 0;
|
|
101
|
+
if (sep - BB_EDGEBIAS * t_fabs(sep) > sep_best && sep > sep_face) { sep_best = sep; code = 6 + 3 * i + j; }
|
|
102
|
+
}
|
|
103
|
+
if (code < 0) return 0;
|
|
104
|
+
int edge_i = 0, edge_j = 0, i1 = 0, i2 = 0;
|
|
105
|
+
T axis[3] = {T(0.f), T(0.f), T(0.f)};
|
|
106
|
+
if (code >= 6) { // an edge axis within ~8 degrees of the best face axis yields to it unless 5% deeper
|
|
107
|
+
edge_i = (code - 6) / 3;
|
|
108
|
+
edge_j = (code - 6) % 3;
|
|
109
|
+
i1 = (edge_i + 1) % 3;
|
|
110
|
+
i2 = (edge_i + 2) % 3;
|
|
111
|
+
axis[i1] = -rot[i2][edge_j];
|
|
112
|
+
axis[i2] = rot[i1][edge_j];
|
|
113
|
+
T len = t_sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]);
|
|
114
|
+
if (len > 0.f) for (int k = 0; k < 3; k++) axis[k] = axis[k] / len;
|
|
115
|
+
T face_dot;
|
|
116
|
+
if (code_face < 3) {
|
|
117
|
+
face_dot = t_fabs(axis[code_face]);
|
|
118
|
+
} else {
|
|
119
|
+
const int f = code_face - 3;
|
|
120
|
+
face_dot = t_fabs(axis[0] * rot[0][f] + axis[1] * rot[1][f] + axis[2] * rot[2][f]);
|
|
121
|
+
}
|
|
122
|
+
if (face_dot > 0.99f && sep_best < sep_face + 0.05f * t_fabs(sep_face) + BB_MINVAL) {
|
|
123
|
+
code = code_face;
|
|
124
|
+
sep_best = sep_face;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (code >= 6) { // stage 2a: one edge-edge contact
|
|
128
|
+
const int j1 = (edge_j + 1) % 3, j2 = (edge_j + 2) % 3;
|
|
129
|
+
if (axis[0] * pos21[0] + axis[1] * pos21[1] + axis[2] * pos21[2] < 0.f)
|
|
130
|
+
for (int k = 0; k < 3; k++) axis[k] = -axis[k];
|
|
131
|
+
T a2[3];
|
|
132
|
+
for (int c = 0; c < 3; c++) a2[c] = axis[0] * rot[0][c] + axis[1] * rot[1][c] + axis[2] * rot[2][c];
|
|
133
|
+
int amb1 = -1, amb2 = -1;
|
|
134
|
+
if (t_fabs(axis[i1]) < BB_SGNEPS) amb1 = i1;
|
|
135
|
+
else if (t_fabs(axis[i2]) < BB_SGNEPS) amb1 = i2;
|
|
136
|
+
if (t_fabs(a2[j1]) < BB_SGNEPS) amb2 = j1;
|
|
137
|
+
else if (t_fabs(a2[j2]) < BB_SGNEPS) amb2 = j2;
|
|
138
|
+
T d2[3] = {rot[0][edge_j], rot[1][edge_j], rot[2][edge_j]};
|
|
139
|
+
T b = d2[edge_i];
|
|
140
|
+
T denom = 1.f - b * b;
|
|
141
|
+
T w1[3] = {T(0.f), T(0.f), T(0.f)}, w2[3] = {T(0.f), T(0.f), T(0.f)};
|
|
142
|
+
T best_d2 = T(BB_MAXVAL);
|
|
143
|
+
for (int v1 = 0; v1 < (amb1 >= 0 ? 2 : 1); v1++)
|
|
144
|
+
for (int v2 = 0; v2 < (amb2 >= 0 ? 2 : 1); v2++) {
|
|
145
|
+
T c1[3] = {T(0.f), T(0.f), T(0.f)}, cc[3] = {T(0.f), T(0.f), T(0.f)}, c2[3];
|
|
146
|
+
c1[i1] = T(axis[i1] >= 0.f ? s1[i1] : -s1[i1]);
|
|
147
|
+
c1[i2] = T(axis[i2] >= 0.f ? s1[i2] : -s1[i2]);
|
|
148
|
+
if (amb1 >= 0 && v1 != 0) c1[amb1] = -c1[amb1];
|
|
149
|
+
cc[j1] = T(a2[j1] >= 0.f ? -s2[j1] : s2[j1]);
|
|
150
|
+
cc[j2] = T(a2[j2] >= 0.f ? -s2[j2] : s2[j2]);
|
|
151
|
+
if (amb2 >= 0 && v2 != 0) cc[amb2] = -cc[amb2];
|
|
152
|
+
for (int r = 0; r < 3; r++) c2[r] = rot[r][0] * cc[0] + rot[r][1] * cc[1] + rot[r][2] * cc[2] + pos21[r];
|
|
153
|
+
T e[3] = {c2[0] - c1[0], c2[1] - c1[1], c2[2] - c1[2]};
|
|
154
|
+
T d1e = e[edge_i];
|
|
155
|
+
T d2e = d2[0] * e[0] + d2[1] * e[1] + d2[2] * e[2];
|
|
156
|
+
T s = T(0.f);
|
|
157
|
+
if (denom >= BB_MINVAL) s = (d1e - b * d2e) / denom;
|
|
158
|
+
s = bb_clamp(s, -s1[edge_i], s1[edge_i]);
|
|
159
|
+
T t = bb_clamp(b * s - d2e, -s2[edge_j], s2[edge_j]);
|
|
160
|
+
s = bb_clamp(d1e + b * t, -s1[edge_i], s1[edge_i]);
|
|
161
|
+
T q1[3] = {c1[0], c1[1], c1[2]}, q2[3], g[3];
|
|
162
|
+
q1[edge_i] = s;
|
|
163
|
+
for (int k = 0; k < 3; k++) { q2[k] = c2[k] + d2[k] * t; g[k] = q2[k] - q1[k]; }
|
|
164
|
+
T gap2 = g[0] * g[0] + g[1] * g[1] + g[2] * g[2];
|
|
165
|
+
if (gap2 < best_d2) {
|
|
166
|
+
best_d2 = gap2;
|
|
167
|
+
for (int k = 0; k < 3; k++) { w1[k] = q1[k]; w2[k] = q2[k]; }
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
T dw[3] = {w2[0] - w1[0], w2[1] - w1[1], w2[2] - w1[2]};
|
|
171
|
+
T dist = dw[0] * axis[0] + dw[1] * axis[1] + dw[2] * axis[2];
|
|
172
|
+
if (dist > septol) return 0;
|
|
173
|
+
T mid[3];
|
|
174
|
+
for (int k = 0; k < 3; k++) mid[k] = 0.5f * (w1[k] + w2[k]);
|
|
175
|
+
cdist[0] = dist;
|
|
176
|
+
for (int r = 0; r < 3; r++) {
|
|
177
|
+
cpos[0][r] = R1[3 * r] * mid[0] + R1[3 * r + 1] * mid[1] + R1[3 * r + 2] * mid[2] + p1[r];
|
|
178
|
+
cnrm[r] = R1[3 * r] * axis[0] + R1[3 * r + 1] * axis[1] + R1[3 * r + 2] * axis[2];
|
|
179
|
+
}
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
// stage 2b: the incident face clipped against the reference face (the owner of the winning face axis)
|
|
183
|
+
const bool ref1 = code < 3;
|
|
184
|
+
const int a = ref1 ? code : code - 3;
|
|
185
|
+
const float* sref = ref1 ? s1 : s2;
|
|
186
|
+
const float* sinc = ref1 ? s2 : s1;
|
|
187
|
+
const T* pref = ref1 ? p1 : p2;
|
|
188
|
+
const T* mref = ref1 ? R1 : R2;
|
|
189
|
+
const T* posoi = ref1 ? pos21 : pos12;
|
|
190
|
+
T rinc[3][3]; // the incident box's axes in the reference frame (columns)
|
|
191
|
+
for (int r = 0; r < 3; r++)
|
|
192
|
+
for (int c = 0; c < 3; c++) rinc[r][c] = ref1 ? rot[r][c] : rot[c][r];
|
|
193
|
+
const float sgn = posoi[a] >= 0.f ? 1.f : -1.f;
|
|
194
|
+
int binc = 0;
|
|
195
|
+
for (int k = 1; k < 3; k++)
|
|
196
|
+
if (t_fabs(rinc[a][k]) > t_fabs(rinc[a][binc])) binc = k;
|
|
197
|
+
const float tinc = sgn * rinc[a][binc] > 0.f ? -1.f : 1.f;
|
|
198
|
+
const int ax = (a + 1) % 3, ay = (a + 2) % 3, bu = (binc + 1) % 3, bv = (binc + 2) % 3;
|
|
199
|
+
const int coords[3] = {ax, ay, a};
|
|
200
|
+
T cx[3], du[3], dv[3];
|
|
201
|
+
for (int r = 0; r < 3; r++) {
|
|
202
|
+
const int c = coords[r];
|
|
203
|
+
cx[r] = posoi[c] + tinc * sinc[binc] * rinc[c][binc];
|
|
204
|
+
du[r] = sinc[bu] * rinc[c][bu];
|
|
205
|
+
dv[r] = sinc[bv] * rinc[c][bv];
|
|
206
|
+
}
|
|
207
|
+
cx[2] = sgn * cx[2] - sref[a];
|
|
208
|
+
du[2] = du[2] * sgn;
|
|
209
|
+
dv[2] = dv[2] * sgn;
|
|
210
|
+
T poly[BB_MAXVERT][3];
|
|
211
|
+
for (int k = 0; k < 4; k++) {
|
|
212
|
+
const float su = (k == 0 || k == 3) ? 1.f : -1.f, sv = k < 2 ? 1.f : -1.f;
|
|
213
|
+
for (int r = 0; r < 3; r++) poly[k][r] = cx[r] + su * du[r] + sv * dv[r];
|
|
214
|
+
}
|
|
215
|
+
int nvert = 4;
|
|
216
|
+
nvert = bb_clip(nvert, poly, 0, 1.f, sref[ax]);
|
|
217
|
+
nvert = bb_clip(nvert, poly, 0, -1.f, sref[ax]);
|
|
218
|
+
nvert = bb_clip(nvert, poly, 1, 1.f, sref[ay]);
|
|
219
|
+
nvert = bb_clip(nvert, poly, 1, -1.f, sref[ay]);
|
|
220
|
+
int naccept = 0;
|
|
221
|
+
const float dupe2 = BB_DUPEPS * (sref[ax] * sref[ax] + sref[ay] * sref[ay]);
|
|
222
|
+
for (int k = 0; k < nvert; k++) {
|
|
223
|
+
if (poly[k][2] > margin) continue;
|
|
224
|
+
bool dupe = false;
|
|
225
|
+
for (int q = 0; q < naccept; q++) {
|
|
226
|
+
T dx = cpos[q][0] - poly[k][0], dy = cpos[q][1] - poly[k][1];
|
|
227
|
+
if (dx * dx + dy * dy < dupe2) { dupe = true; break; }
|
|
228
|
+
}
|
|
229
|
+
if (!dupe) {
|
|
230
|
+
for (int r = 0; r < 3; r++) cpos[naccept][r] = poly[k][r];
|
|
231
|
+
naccept++;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (naccept == 0) return 0;
|
|
235
|
+
const float nsign = ref1 ? sgn : -sgn;
|
|
236
|
+
for (int r = 0; r < 3; r++) cnrm[r] = nsign * mref[3 * r + a];
|
|
237
|
+
for (int k = 0; k < naccept; k++) {
|
|
238
|
+
T v[3] = {cpos[k][0], cpos[k][1], cpos[k][2]}, pc[3];
|
|
239
|
+
pc[ax] = v[0];
|
|
240
|
+
pc[ay] = v[1];
|
|
241
|
+
pc[a] = sgn * (sref[a] + 0.5f * v[2]);
|
|
242
|
+
cdist[k] = v[2];
|
|
243
|
+
for (int r = 0; r < 3; r++) cpos[k][r] = mref[3 * r] * pc[0] + mref[3 * r + 1] * pc[1] + mref[3 * r + 2] * pc[2] + pref[r];
|
|
244
|
+
}
|
|
245
|
+
return naccept;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// one contact (slot) of bb_box_box_t: 1 when it exists (dist < 0), its distance, position and normal
|
|
249
|
+
template <class T>
|
|
250
|
+
__device__ __noinline__ int bb_slot_t(const T* p1, const T* R1, const float* s1, const T* p2, const T* R2,
|
|
251
|
+
const float* s2, int slot, T* dist, T* pos, T* nrm) {
|
|
252
|
+
T cd[BB_MAXVERT], cp[BB_MAXVERT][3];
|
|
253
|
+
const int n = bb_box_box_t(p1, R1, s1, p2, R2, s2, 0.f, cd, cp, nrm);
|
|
254
|
+
if (slot < 0 || slot >= n || !(cd[slot] < 0.f)) return 0;
|
|
255
|
+
*dist = cd[slot];
|
|
256
|
+
for (int k = 0; k < 3; k++) pos[k] = cp[slot][k];
|
|
257
|
+
return 1;
|
|
258
|
+
}
|
|
259
|
+
"""
|