SuperDex Physics C++ API
Loading...
Searching...
No Matches
mesh_data.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.
25
26#include <optional>
27#include <string_view>
28
29namespace superdex {
30
31// Forwards:
32struct BlendingDataView;
33struct SkinningDataView;
34struct MeshDataView;
35
36/** @brief Spatial dimensionality of mesh data. */
37inline constexpr int kMeshDataSpaceDim = 3;
38
39/**
40 * @brief Blending data for one source shape within a soft skinned mesh.
41 *
42 * @see BlendingDataView
43 */
45 /** @brief Default constructor. */
46 BlendingData() = default;
47
48 /**
49 * @brief Copy from @ref BlendingDataView.
50 *
51 * @param[in] src Source data.
52 */
53 explicit BlendingData(BlendingDataView const& src);
54
55 /** @brief Name of the soft source shape. */
57 /**
58 * @brief Nested-soft source vertex indices for each target vertex.
59 *
60 * @details Entry `i` identifies the vertex in the nested soft shape for target vertex `i`. The
61 * index is ignored when `weights[i]` is zero. The size equals the number of target vertices.
62 */
64 /**
65 * @brief Nested-soft blend weights for each target vertex.
66 *
67 * @details Entry `i` is in `[0, 1]`, where zero is purely articulated and one is fully
68 * nested-soft. The size equals the number of target vertices.
69 */
71
72#if MOCHI_LANGUAGE_CPP20
73 bool operator==(BlendingData const& other) const = default;
74 bool operator!=(BlendingData const& other) const = default;
75#endif
76
82};
83
84/**
85 * @brief Non-owning view of blending data for one source shape within a soft skinned mesh.
86 *
87 * @see BlendingData
88 */
90 BlendingDataView() = default;
91
92 /**
93 * @brief Implicit conversion from @ref BlendingData.
94 *
95 * @param[in] src Source data.
96 */
98
99 /** @brief See @ref BlendingData::sourceShape. */
100 std::string_view sourceShape;
101 /** @brief See @ref BlendingData::indices. */
103 /** @brief See @ref BlendingData::weights. */
105
106#if MOCHI_LANGUAGE_CPP20
107 bool operator==(BlendingDataView const& other) const = default;
108 bool operator!=(BlendingDataView const& other) const = default;
109#endif
110};
111
112/**
113 * @brief Skinning data for a Mochi mesh.
114 *
115 * @see SkinningDataView
116 */
118 SkinningData() = default; ///< Default constructor
119
120 /**
121 * @brief Copy from @ref SkinningDataView.
122 *
123 * @param[in] src Source data.
124 */
125 explicit SkinningData(SkinningDataView const& src);
126
127 int weightsPerNode = 0; ///< Number of weights and indices per node being skinned.
128 DynamicArray<int> indices; ///< Indices for each node. Size = numNodes * weightsPerNode.
129 DynamicArray<real> weights; ///< Weights for each node. Size = numNodes * weightsPerNode.
130
131#if MOCHI_LANGUAGE_CPP20
132 bool operator==(SkinningData const& other) const = default;
133 bool operator!=(SkinningData const& other) const = default;
134#endif
135
141};
142
143/**
144 * @brief A non-owning view of the skinning data for a Mochi mesh.
145 *
146 * @see SkinningData
147 */
149 SkinningDataView() = default;
150
151 /**
152 * @brief Implicit conversion from @ref SkinningData.
153 *
154 * @param[in] src Source data.
155 */
156 SkinningDataView(SkinningData const& src);
157
158 int weightsPerNode = 0; ///< Number of weights and indices per node being skinned.
159 Span<int const> indices; ///< Indices for each node. Size = numNodes * weightsPerNode.
160 Span<real const> weights; ///< Weights for each node. Size = numNodes * weightsPerNode.
161
162#if MOCHI_LANGUAGE_CPP20
163 bool operator==(SkinningDataView const& other) const = default;
164 bool operator!=(SkinningDataView const& other) const = default;
165#endif
166};
167
168/**
169 * @brief Mesh data for a Mochi actor or model file.
170 *
171 * @see MeshDataView
172 */
173struct MeshData {
174 MeshData() = default; ///< Default constructor
175
176 /**
177 * @brief Copy from @ref MeshDataView.
178 *
179 * @param[in] src Source data.
180 */
181 explicit MeshData(MeshDataView const& src);
182
183 /**
184 * @brief Number of nodes (vertices) per element.
185 *
186 * @note 2 for polyline mesh, 3 for triangle mesh, 4 for tetrahedral mesh
187 */
189
190 /**
191 * @brief Flat array of node coordinate values [m].
192 *
193 * @note Size must be a multiple of @ref kMeshDataSpaceDim.
194 */
196
197 /**
198 * @brief Flat array of node indices forming the elements.
199 *
200 * @note Size must be a multiple of @ref nodesPerElement.
201 */
203
204 /** @brief Optional skinning */
205 std::optional<SkinningData> skinning;
206
207 /** @brief Return the number of nodes */
208 int GetNumNodes() const;
209
210 /** @brief Return the number of elements */
211 int GetNumElements() const;
212
213 /** @brief Return true if the mesh is empty. */
214 [[nodiscard]] bool IsEmpty() const;
215
216#if MOCHI_LANGUAGE_CPP20
217 bool operator==(MeshData const& other) const = default;
218 bool operator!=(MeshData const& other) const = default;
219#endif
220
227};
228
229/**
230 * @brief A non-owning view of the mesh data for a Mochi actor or model file.
231 *
232 * @see MeshData
233 */
235 MeshDataView() = default;
236
237 /**
238 * @brief Implicit conversion from @ref MeshData.
239 *
240 * @param[in] src Source data.
241 */
242 MeshDataView(MeshData const& src);
243
244 /**
245 * @brief Number of nodes (vertices) per element.
246 *
247 * @note 2 for polyline mesh, 3 for triangle mesh, 4 for tetrahedral mesh
248 */
250
251 /**
252 * @brief Flat array of node coordinate values [m].
253 *
254 * @note Size must be a multiple of @ref kMeshDataSpaceDim.
255 */
257
258 /**
259 * @brief Flat array of node indices forming the elements.
260 *
261 * @note Size must be a multiple of @ref nodesPerElement.
262 */
264
265 /** @brief Optional skinning */
266 std::optional<SkinningDataView> skinning;
267
268 /** @brief Return the number of nodes */
269 int GetNumNodes() const;
270
271 /** @brief Return the number of elements */
272 int GetNumElements() const;
273
274 /** @brief Return true if the mesh is empty. */
275 [[nodiscard]] bool IsEmpty() const;
276
277#if MOCHI_LANGUAGE_CPP20
278 bool operator==(MeshDataView const& other) const = default;
279 bool operator!=(MeshDataView const& other) const = default;
280#endif
281};
282
283} // namespace superdex
284
285#include "mesh_data_inl.h"
A dynamically resizable array with syntax and behavior similar to std::pmr::vector.
constexpr int kMeshDataSpaceDim
Spatial dimensionality of mesh data.
Definition mesh_data.h:37
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > DynamicString
Alias for std::string using a polymorphic superdex::Allocator pointer.
#define MOCHI_STRUCT_END()
Definition reflection.h:279
#define MOCHI_FIELD(name)
Definition reflection.h:293
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:278
#define MOCHI_ATTRIBUTE(...)
Definition reflection.h:298
Non-owning view of blending data for one source shape within a soft skinned mesh.
Definition mesh_data.h:89
bool operator!=(BlendingDataView const &other) const =default
Span< int const > indices
See BlendingData::indices.
Definition mesh_data.h:102
Span< real const > weights
See BlendingData::weights.
Definition mesh_data.h:104
bool operator==(BlendingDataView const &other) const =default
std::string_view sourceShape
See BlendingData::sourceShape.
Definition mesh_data.h:100
Blending data for one source shape within a soft skinned mesh.
Definition mesh_data.h:44
DynamicString sourceShape
Name of the soft source shape.
Definition mesh_data.h:56
bool operator!=(BlendingData const &other) const =default
BlendingData()=default
Default constructor.
bool operator==(BlendingData const &other) const =default
DynamicArray< int > indices
Nested-soft source vertex indices for each target vertex.
Definition mesh_data.h:63
DynamicArray< real > weights
Nested-soft blend weights for each target vertex.
Definition mesh_data.h:70
A non-owning view of the mesh data for a Mochi actor or model file.
Definition mesh_data.h:234
Span< int const > connectivity
Flat array of node indices forming the elements.
Definition mesh_data.h:263
int GetNumElements() const
Return the number of elements.
bool operator==(MeshDataView const &other) const =default
int GetNumNodes() const
Return the number of nodes.
bool operator!=(MeshDataView const &other) const =default
int nodesPerElement
Number of nodes (vertices) per element.
Definition mesh_data.h:249
bool IsEmpty() const
Return true if the mesh is empty.
std::optional< SkinningDataView > skinning
Optional skinning.
Definition mesh_data.h:266
Span< real const > coordinates
Flat array of node coordinate values [m].
Definition mesh_data.h:256
Mesh data for a Mochi actor or model file.
Definition mesh_data.h:173
int GetNumNodes() const
Return the number of nodes.
bool operator!=(MeshData const &other) const =default
bool IsEmpty() const
Return true if the mesh is empty.
int nodesPerElement
Number of nodes (vertices) per element.
Definition mesh_data.h:188
DynamicArray< real > coordinates
Flat array of node coordinate values [m].
Definition mesh_data.h:195
bool operator==(MeshData const &other) const =default
MeshData()=default
Default constructor.
DynamicArray< int > connectivity
Flat array of node indices forming the elements.
Definition mesh_data.h:202
int GetNumElements() const
Return the number of elements.
std::optional< SkinningData > skinning
Optional skinning.
Definition mesh_data.h:205
A non-owning view of the skinning data for a Mochi mesh.
Definition mesh_data.h:148
int weightsPerNode
Number of weights and indices per node being skinned.
Definition mesh_data.h:158
bool operator!=(SkinningDataView const &other) const =default
bool operator==(SkinningDataView const &other) const =default
Span< int const > indices
Indices for each node. Size = numNodes * weightsPerNode.
Definition mesh_data.h:159
Span< real const > weights
Weights for each node. Size = numNodes * weightsPerNode.
Definition mesh_data.h:160
Skinning data for a Mochi mesh.
Definition mesh_data.h:117
bool operator==(SkinningData const &other) const =default
int weightsPerNode
Number of weights and indices per node being skinned.
Definition mesh_data.h:127
DynamicArray< real > weights
Weights for each node. Size = numNodes * weightsPerNode.
Definition mesh_data.h:129
bool operator!=(SkinningData const &other) const =default
SkinningData()=default
Default constructor.
DynamicArray< int > indices
Indices for each node. Size = numNodes * weightsPerNode.
Definition mesh_data.h:128