SuperDex Physics C++ API
Loading...
Searching...
No Matches
grid_sdf_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.
24
25namespace superdex {
26
27/**
28 * @brief The maximum voxel size for an SDF will be determined by one of these measurements scaled
29 * by @ref GridSdfParams::resolutionDelta.
30 */
32 /**
33 * @brief Use the largest dimension of the mesh's axis-aligned bounding box (AABB) as reference.
34 */
36
37 /** @brief Use the smallest dimension of the mesh's AABB as reference. */
39
40 /** @brief Use the average of all three AABB dimensions as reference. */
42
43 /** @brief Use the largest edge length in the mesh as reference. */
45
46 /** @brief Use the smallest edge length in the mesh as reference. */
48
49 /** @brief Use the average edge length in the mesh as reference. */
51
52 /**
53 * @brief Use @ref GridSdfParams::resolutionDelta to set the maximum voxel size in meters (no
54 * scaling based on the features of the mesh nor AABB).
55 */
57
58 /** @brief Total number of resolution modes. */
60};
61
62} // namespace superdex
63
65MOCHI_ENUM_ITEM(LargestAxis);
66MOCHI_ENUM_ITEM(SmallestAxis);
67MOCHI_ENUM_ITEM(MeanAxis);
68MOCHI_ENUM_ITEM(LargestEdge);
69MOCHI_ENUM_ITEM(SmallestEdge);
70MOCHI_ENUM_ITEM(MeanEdge);
71MOCHI_ENUM_ITEM(Explicit);
72MOCHI_ENUM_COUNT(Count);
74
75namespace superdex {
76
77/**
78 * @brief Default value for @ref GridSdfParams::boundaryPaddingDist [m]
79 *
80 * @note For best performance, an SDF should have more padding than the actor's contact penalty
81 * threshold distance. This default was chosen to be 5X the default penalty threshold distance so
82 * that an SDF will have sufficient padding when loaded with any scale value greater than or equal
83 * to 0.2 (per axis).
84 *
85 * @see ContactParams::penaltyThresholdDefault
86 */
89
90/**
91 * @brief Parameters controlling the resolution of grid-based Signed Distance Fields (SDF).
92 *
93 * @details A GridSdf represents the SDF to a closed surface mesh as a 3D grid where each vertex
94 * stores the signed distance to the surface mesh. The SDF grid resolution and bounds are controlled
95 * by these parameters.
96 */
98 /**
99 * @brief Defines the mesh feature used as reference measurement for computing the voxel size.
100 *
101 * @see resolutionDelta
102 */
104
105 /**
106 * @brief The maximum voxel size will be @ref resolutionDelta times the reference measurement
107 * computed using @ref resolutionMode.
108 *
109 * @note The actual voxel size may be smaller because the number of grid cells will be rounded up
110 * to an integer value and clamped to a minimum of @ref minGridResolution.
111 * @note Increasing @ref resolutionDelta will result in larger voxels. Doing so will make it
112 * harder for the SDF to resolve fine details of the mesh, but it will save memory and improve SDF
113 * generation speed.
114 * @note Decreasing @ref resolutionDelta will improve the SDF's ability to resolve fine details,
115 * but it will take more memory and more time to generate. This cost scales proportional to N^3.
116 * Use with care.
117 *
118 * @see resolutionMode
119 */
120 Real3 resolutionDelta = {0.25_r, 0.25_r, 0.25_r};
121
122 /**
123 * @brief Additional distance (in meters) to expand the mesh's axis-aligned bounding box (AABB)
124 * when determining the SDF grid bounds.
125 *
126 * @details The SDF grid will cover the mesh's AABB expanded by this distance in all directions.
127 * This ensures the SDF has valid distance values even slightly outside the mesh's AABB.
128 *
129 * @note In practice, this value should be greater than the value returned by @ref
130 * ContactParams::GetPenaltyThresholdDist. If the SDF did not have enough padding, then Mochi
131 * would have to use a less efficient algorithm for collision detection, but it would still work.
132 * @note When you load a model and bake a uniform scale value less than 1.0, the model's
133 * pre-computed SDF will also be scaled, resulting in less absolute padding. The default padding
134 * value is larger than the default contact penalty threshold distance for this reason.
135 *
136 * @see kGridSdfDefaultBoundaryPadding
137 */
139
140 /**
141 * @brief The minimum grid resolution measured in number of voxels per axis.
142 *
143 * @note This may override the voxel count (and voxel size) computed using @ref resolutionMode and
144 * @ref resolutionDelta.
145 */
147
148#if MOCHI_LANGUAGE_CPP20
149 bool operator==(GridSdfParams const&) const = default;
150#endif
151
152 // clang-format off
159 // clang-format on
160};
161
162} // namespace superdex
GridSdfResolutionMode
The maximum voxel size for an SDF will be determined by one of these measurements scaled by GridSdfPa...
@ MeanAxis
Use the average of all three AABB dimensions as reference.
@ LargestAxis
Use the largest dimension of the mesh's axis-aligned bounding box (AABB) as reference.
@ LargestEdge
Use the largest edge length in the mesh as reference.
@ MeanEdge
Use the average edge length in the mesh as reference.
@ Explicit
Use GridSdfParams::resolutionDelta to set the maximum voxel size in meters (no scaling based on the f...
@ SmallestEdge
Use the smallest edge length in the mesh as reference.
@ SmallestAxis
Use the smallest dimension of the mesh's AABB as reference.
static constexpr real kGridSdfDefaultBoundaryPadding
Default value for GridSdfParams::boundaryPaddingDist [m].
NdArray< int, 3 > Int3
Definition nd_array.h:138
NdArray< real, 3 > Real3
Definition nd_array.h:106
@ 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
Parameters for contact mechanics simulation.
real penaltyThresholdDefault
Default contact detection threshold [m].
Parameters controlling the resolution of grid-based Signed Distance Fields (SDF).
bool operator==(GridSdfParams const &) const =default
Real3 resolutionDelta
The maximum voxel size will be resolutionDelta times the reference measurement computed using resolut...
real boundaryPaddingDist
Additional distance (in meters) to expand the mesh's axis-aligned bounding box (AABB) when determinin...
GridSdfResolutionMode resolutionMode
Defines the mesh feature used as reference measurement for computing the voxel size.
Int3 minGridResolution
The minimum grid resolution measured in number of voxels per axis.