SuperDex Physics C++ API
Loading...
Searching...
No Matches
contact_params.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19// PLEASE DO NOT ADD OTHER INCLUDES HERE. This header is included in the mochi_physics public API.
22
23namespace superdex {
24
25/**
26 * @brief Parameters for contact mechanics simulation.
27 *
28 * @note For each field without an actor-pair override, contact between a colliding actor and a
29 * collider uses the collider's contact parameter (not the colliding actor's). The exceptions are:
30 * - For friction and dissipation coefficients (viscousFrictionCoefficient,
31 * coulombFrictionCoefficient, normalViscousDampingCoefficient), the geometric mean of the
32 * colliding and collider's coefficients is used. This disables friction/dissipation if either
33 * of them does.
34 * - For penalty coefficient (penaltyCoefficient) and friction velocity threshold
35 * (frictionFalloffVel), the geometric mean of the colliding and collider's values is used,
36 * except if the collider is static in which case the colliding's values are used.
37 *
38 * @see Scene::SetContactPairParamsOverride
39 */
41 ContactParams() = default;
42
43 /**
44 * @brief Construct ContactParams with all parameters explicitly specified.
45 *
46 * @param[in] penaltyCoefficient See @ref penaltyCoefficient.
47 * @param[in] penaltySmoothingHalfDistance See @ref penaltySmoothingHalfDistance.
48 * @param[in] penaltyThresholdDefault See @ref penaltyThresholdDefault.
49 * @param[in] penaltyThresholdExtraPadding See @ref penaltyThresholdExtraPadding.
50 * @param[in] frictionWithColliderNormal See @ref frictionWithColliderNormal.
51 * @param[in] maxAlignmentNormals See @ref maxAlignmentNormals.
52 * @param[in] viscousFrictionCoefficient See @ref viscousFrictionCoefficient.
53 * @param[in] coulombFrictionCoefficient See @ref coulombFrictionCoefficient.
54 * @param[in] frictionFalloffVel See @ref frictionFalloffVel.
55 * @param[in] normalViscousDampingCoefficient See @ref normalViscousDampingCoefficient.
56 * @param[in] distanceErrorBound See @ref distanceErrorBound.
57 * @param[in] objScale See @ref objScale.
58 * @param[in] collidingPenaltyLengthScale See @ref collidingPenaltyLengthScale.
59 *
60 * @note Must take every parameter in order.
61 * @note Used when converting types to/from the C API.
62 */
77
78 // Parameters for penalty contact.
79
80 /**
81 * @brief Stiffness of the contact penalty force [Pa/m].
82 *
83 * @note Must be finite and strictly positive.
84 * @note Higher penalties create stiffer contacts and reduce penetration.
85 * @note Arbitrarily large penalties may degrade stability.
86 * @note The default penalty is appropriate for actors with default density. For actors with much
87 * higher/lower density than the default density, the penalty coefficient may need to be
88 * increased/decreased accordingly.
89 * @note Without an actor-pair override for this field, the value used in a collision is the
90 * geometric mean of the colliding and collider's coefficients. The exception is if the collider
91 * is static, in which case the colliding's penalty is used.
92 * @note The penalty coefficient is additionally scaled by length-scale corrections when the
93 * colliding or collider integrates contact over a non-2D manifold (e.g., rod, shell). See @ref
94 * collidingPenaltyLengthScale.
95 */
97
98 /**
99 * @brief PolyReLU smoothing half-width [m].
100 *
101 * @details The penalty force transitions from 0 to linear over the decreasing distance range
102 * (penaltyThreshold, penaltyThreshold - 2 * @ref penaltySmoothingHalfDistance).
103 *
104 * @note Must be finite and not negative.
105 * @note Larger smoothing distances improve stability but may increase penetration.
106 * @note Smoothing distance is expected to be small relative to the collider geometry.
107 */
109
110 /**
111 * @brief Default contact detection threshold [m].
112 *
113 * @details The penalty force transitions from 0 to linear over the decreasing distance range
114 * (penaltyThreshold, penaltyThreshold - 2 * @ref penaltySmoothingHalfDistance).
115 *
116 * @note Must be finite. Negative values are legal.
117 * @note If the colliding actor has @ref ColliderType::None or @ref ColliderType::PointCloud,
118 * penaltyThreshold = penaltyThresholdDefault + @ref penaltyThresholdExtraPadding. Otherwise,
119 * penaltyThreshold = penaltyThresholdDefault.
120 *
121 * @see penaltyThresholdExtraPadding, GetPenaltyThresholdDist
122 */
124
125 /**
126 * @brief Extra padding [m] added to the default contact detection threshold if the colliding
127 * actor has @ref ColliderType::None or @ref ColliderType::PointCloud.
128 *
129 * @note Must be finite and not negative.
130 * @note Extra padding is useful to avoid tunneling through thin actors when the other actor has
131 * @ref ColliderType::None or @ref ColliderType::PointCloud.
132 *
133 * @see penaltyThresholdDefault, GetPenaltyThresholdDist
134 */
136
137 // Parameters for friction
138
139 /**
140 * @brief Use collider's normal (normalized SDF gradient) for friction direction if true, or the
141 * colliding's surface normal at the sample point if false.
142 *
143 * @note For co-dimensional colliding actors with ambiguous normals, the collider's normal is
144 * always used regardless of frictionWithColliderNormal.
145 */
147
148 /**
149 * @brief Maximum normal alignment threshold.
150 *
151 * @details Normal alignment is defined as the dot product between colliding and collider normals.
152 * Contact is disabled for sample points whose normal alignment exceeds this threshold. This
153 * prevents sample points from being trapped inside the collider when penetration is large.
154 *
155 * @note Must be in [-1, 1]. -1 allows contact only for perfectly opposing normals, 1 allows all
156 * contacts.
157 * @note For co-dimensional colliding actors with ambiguous normals, contact is not disabled
158 * regardless of maxAlignmentNormals (normal alignment cannot be computed).
159 */
161
162 /**
163 * @brief Viscous friction coefficient [s/m].
164 *
165 * @note Friction force is proportional to contact force and tangential velocity.
166 * @note Must be finite and not negative.
167 * @note Both viscousFrictionCoefficient and @ref coulombFrictionCoefficient can be >0.
168 * @note Without an actor-pair override for this field, the value used in a collision is the
169 * geometric mean of the colliding and collider's coefficients. This disables viscous friction if
170 * either of them does.
171 */
173
174 /**
175 * @brief Coulomb friction coefficient (dimensionless).
176 *
177 * @note Must be finite and not negative.
178 * @note Both @ref viscousFrictionCoefficient and coulombFrictionCoefficient can be >0.
179 * @note Without an actor-pair override for this field, the value used in a collision is the
180 * geometric mean of the colliding and collider's coefficients. This disables Coulomb friction if
181 * either of them does.
182 */
184
185 /**
186 * @brief Velocity threshold for Coulomb friction smoothing [m/s].
187 *
188 * @details For C1Regularized, the Coulomb friction force smoothly transitions from 0 to full
189 * strength as tangential velocity increases from 0 to frictionFalloffVel (compact support). For
190 * CinfRegularized, the force asymptotically approaches full strength with no compact support
191 * boundary; frictionFalloffVel controls the regularization scale.
192 *
193 * @note Must be finite and not negative. For CinfRegularized, a value of zero is clamped
194 * internally to avoid numerical issues.
195 * @note Smaller velocity thresholds improve physical accuracy but may degrade stability.
196 * @note Without an actor-pair override for this field, the value used in a collision is the
197 * geometric mean of the colliding and collider's thresholds. The exception is if the collider is
198 * static, in which case the colliding's threshold is used.
199 */
201
202 /**
203 * @brief Normal viscous damping coefficient [s/m].
204 *
205 * @details Damping force in the normal direction, proportional to the elastic normal contact
206 * force and the normal velocity. Analogous to @ref viscousFrictionCoefficient but acting in the
207 * normal direction instead of tangentially.
208 *
209 * @warning The calibration diverges as CoR approaches zero, which may cause numerical problems
210 * when approaching fully-inelastic collisions.
211 *
212 * @note Must be finite and not negative.
213 * @note Without an actor-pair override for this field, the value used in a collision is the
214 * geometric mean of the colliding and collider's coefficients. This disables normal damping if
215 * either of them does.
216 * @note The resulting coefficient of restitution (CoR) is velocity-dependent. For a
217 * characteristic impact velocity,
218 * @c experimental::CalibrateNormalViscousDampingCoefficient computes the coefficient that
219 * approximates a target CoR, while @c experimental::EffectiveCoefficientOfRestitution recovers
220 * the CoR produced by a coefficient.
221 * @note Because the damping force depends on the normal velocity at each contact point, it also
222 * introduces rolling resistance: a body rolling on a surface dissipates energy through the
223 * differing normal velocities across its contacting region.
224 */
226
227 // Experimental parameters
228
229 /**
230 * @brief [Experimental] Padding [m] added to the collider's bounding volume for collision
231 * culling.
232 *
233 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
234 * your own risk.
235 *
236 * @note Must be finite.
237 * @note Useful, for example, with approximate SDFs (e.g., deep flow map) to compensate for
238 * potentially overestimating the true distance.
239 */
241
242 /**
243 * @brief [Experimental] Object scale relative to default size (dimensionless). Used by deep flow
244 * only.
245 *
246 * @warning Deep flow is an experimental feature. It may be changed or removed in the future. Use
247 * at your own risk.
248 *
249 * @note Must be finite and strictly positive.
250 */
252
253 /**
254 * @brief [Experimental] Length scale [m] used to correct the penalty coefficient when the
255 * colliding body integrates contact traction over a lower-than-two-dimensional manifold, such as
256 * a rod or point mass. E.g., the penalty is scaled by this value if the colliding body lumps
257 * contact tractions on a line, or this value squared if lumping contact forces on a point.
258 *
259 * @warning Contact with lower-dimensional bodies is an experimental feature. It may be changed or
260 * removed in the future. Use at your own risk.
261 *
262 * @note Must be finite and strictly positive.
263 * @note This value is not used in the most common case, where contact traction is integrated over
264 * a two-dimensional surface.
265 * @note The colliding body's value is always used in a contact pair, because the colliding body
266 * determines the dimension of the contact traction integral.
267 */
269
270 /**
271 * @brief Get the total contact detection threshold.
272 *
273 * @param addPadding If true, includes @ref penaltyThresholdExtraPadding.
274 *
275 * @return Total contact detection threshold [m].
276 */
277 real GetPenaltyThresholdDist(bool addPadding) const;
278
279#if MOCHI_LANGUAGE_CPP20
280 bool operator==(ContactParams const&) const = default;
281#endif
282
283 // clang-format off
299 // clang-format on
300};
301
302/**
303 * @brief Selects which Coulomb friction smoothing model to use.
304 *
305 * @see ContactParams::frictionFalloffVel
306 */
308 /**
309 * @brief C1-smoothed Coulomb friction with compact support: friction transitions linearly from 0
310 * to full strength over [0, @ref ContactParams::frictionFalloffVel].
311 */
313
314 /**
315 * @brief C-infinity regularized Coulomb friction with no compact support: friction asymptotically
316 * approaches full strength. @ref ContactParams::frictionFalloffVel controls the regularization
317 * scale.
318 */
320
321 /** @brief Number of friction model enum values. */
323
324 /** @brief Default Coulomb friction model. */
326};
327
328} // namespace superdex
329
335
336namespace superdex {
337
338/**
339 * @brief Collision detection geometry for an @ref Actor.
340 *
341 * @note This setting controls how OTHER actors detect contact with this actor. It does not affect
342 * how this actor detects contact with other actors.
343 */
344enum class ColliderType {
345 /**
346 * @brief No collision representation. Other actors cannot detect contact with this actor.
347 *
348 * @note It does NOT prevent this actor from detecting contact with other actors.
349 */
351
352 /**
353 * @brief Automatic collider type selection based on the actor's shape.
354 *
355 * @note Mochi will select the most appropriate collider type based on the actor's shape and type:
356 * - Implicit sphere shapes: @ref ColliderType::Sphere
357 * - Implicit plane shapes: @ref ColliderType::Plane
358 * - Mesh shapes on volumetric actors (e.g., rigid, soft): @ref ColliderType::Sdf
359 * - Shell and rod actors: @ref ColliderType::PointCloud
360 *
361 * @note If Auto is set on an actor, a valid collider type will be assigned even if the shape's
362 * default collider type is @ref ColliderType::None. If you want @ref ColliderType::None, set
363 * @ref ColliderType::None explicitly as your collider type.
364 *
365 * @note After initialization, @ref Actor::GetColliderType will return the selected type, not
366 * @ref ColliderType::Auto.
367 */
369
370 /**
371 * @brief Represent the actor by an approximating sphere derived from its bounding volume.
372 *
373 * @note For shapes with a sphere bounding volume, that sphere is used. For shapes with an
374 * OBB/AABB bounding volume, the inscribed sphere is used. Otherwise, a true bounding sphere is
375 * computed.
376 * @note Fast but only accurate for spherical geometries.
377 * @note Only supported for rigid actors and articulated links.
378 */
380
381 /**
382 * @brief Represent the actor by its axis-aligned bounding box (AABB), in the actor's local frame.
383 *
384 * @note Fast but only accurate for box geometries.
385 * @note Only supported for rigid actors and articulated links.
386 */
388
389 /**
390 * @brief [Experimental] Represent the actor by its surface mesh.
391 *
392 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
393 * your own risk.
394 *
395 * @note Performance is slow.
396 * @note Only supported for rigid actors and articulated links.
397 */
399
400 /**
401 * @brief Represent the actor as an infinite plane.
402 *
403 * @note Only supported for static rigid actors whose shape is an implicit plane.
404 */
406
407 /**
408 * @brief Grid-based Signed Distance Field (SDF) collision representation.
409 *
410 * @note Uses a 3D grid storing the distance to the closest point in the actor's surface.
411 * @note Accurate for closed non-intersecting geometries provided the grid resolution is
412 * sufficient.
413 * @note If the grid is not baked in the actor's Shape, it is computed at initialization
414 * (expensive).
415 * @note Also supported for soft actors via SDF mapping.
416 *
417 * @see GridSdfParams
418 */
420
421 /**
422 * @brief Point-cloud collision representation.
423 *
424 * @details Contacts are detected by proximity queries between collider-side sample points and
425 * colliding-side sample points. Only other point-cloud colliders can collide with this type.
426 */
428
429 /** @brief Number of collider type enum values. */
431};
432} // namespace superdex
433
445
446#include "contact_params_inl.h"
CoulombFrictionModel
Selects which Coulomb friction smoothing model to use.
@ CinfRegularized
C-infinity regularized Coulomb friction with no compact support: friction asymptotically approaches f...
@ C1Regularized
C1-smoothed Coulomb friction with compact support: friction transitions linearly from 0 to full stren...
ColliderType
Collision detection geometry for an Actor.
@ Auto
Automatic collider type selection based on the actor's shape.
@ Mesh
[Experimental] Represent the actor by its surface mesh.
@ Sdf
Grid-based Signed Distance Field (SDF) collision representation.
@ PointCloud
Point-cloud collision representation.
@ None
Invalid actor type.
Definition mochi_enums.h:26
@ Count
Number of actor type enum values.
Definition mochi_enums.h:38
#define MOCHI_ENUM_COUNT(name)
Definition reflection.h:275
#define MOCHI_ENUM_END()
Definition reflection.h:276
#define MOCHI_STRUCT_END()
Definition reflection.h:279
#define MOCHI_ENUM_BEGIN(name)
Definition reflection.h:273
#define MOCHI_FIELD(name)
Definition reflection.h:293
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:278
#define MOCHI_ATTRIBUTE(...)
Definition reflection.h:298
#define MOCHI_ENUM_ITEM(name)
Definition reflection.h:274
Data for an implicit box within a model file.
Definition box.h:31
Parameters for contact mechanics simulation.
real maxAlignmentNormals
Maximum normal alignment threshold.
real collidingPenaltyLengthScale
[Experimental] Length scale [m] used to correct the penalty coefficient when the colliding body integ...
bool operator==(ContactParams const &) const =default
real coulombFrictionCoefficient
Coulomb friction coefficient (dimensionless).
real penaltyThresholdDefault
Default contact detection threshold [m].
real penaltyCoefficient
Stiffness of the contact penalty force [Pa/m].
real distanceErrorBound
[Experimental] Padding [m] added to the collider's bounding volume for collision culling.
real normalViscousDampingCoefficient
Normal viscous damping coefficient [s/m].
real penaltySmoothingHalfDistance
PolyReLU smoothing half-width [m].
real objScale
[Experimental] Object scale relative to default size (dimensionless).
real GetPenaltyThresholdDist(bool addPadding) const
Get the total contact detection threshold.
real viscousFrictionCoefficient
Viscous friction coefficient [s/m].
bool frictionWithColliderNormal
Use collider's normal (normalized SDF gradient) for friction direction if true, or the colliding's su...
real penaltyThresholdExtraPadding
Extra padding [m] added to the default contact detection threshold if the colliding actor has Collide...
real frictionFalloffVel
Velocity threshold for Coulomb friction smoothing [m/s].