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 BlendingData() = default; ///< Default constructor
46
47 /**
48 * @brief Copy from @ref BlendingDataView.
49 *
50 * @param[in] src Source data.
51 */
52 explicit BlendingData(BlendingDataView const& src);
53
54 DynamicString sourceShape; ///< Name of the soft source shape.
55 DynamicArray<int> indices; ///< Indices for blending. Size = numNodes * 2.
56 DynamicArray<real> weights; ///< Weights for blending Size = numNodes * 2.
57
58#if MOCHI_LANGUAGE_CPP20
59 bool operator==(BlendingData const& other) const = default;
60 bool operator!=(BlendingData const& other) const = default;
61#endif
62
68};
69
70/**
71 * @brief A non-owning view of the data blending data for one source shape within a soft skinned
72 * mesh.
73 *
74 * @see BlendingData
75 */
77 BlendingDataView() = default;
78
79 /**
80 * @brief Implicit conversion from @ref BlendingData.
81 *
82 * @param[in] src Source data.
83 */
85
86 std::string_view sourceShape; ///< Name of the soft source shape
87 Span<int const> indices; ///< Indices for blending. Size = numNodes * 2.
88 Span<real const> weights; ///< Weights for blending Size = numNodes * 2.
89
90#if MOCHI_LANGUAGE_CPP20
91 bool operator==(BlendingDataView const& other) const = default;
92 bool operator!=(BlendingDataView const& other) const = default;
93#endif
94};
95
96/**
97 * @brief Skinning data for a Mochi mesh.
98 *
99 * @see SkinningDataView
100 */
102 SkinningData() = default; ///< Default constructor
103
104 /**
105 * @brief Copy from @ref SkinningDataView.
106 *
107 * @param[in] src Source data.
108 */
109 explicit SkinningData(SkinningDataView const& src);
110
111 int weightsPerNode = 0; ///< Number of weights and indices per node being skinned.
112 DynamicArray<int> indices; ///< Indices for each node. Size = numNodes * weightsPerNode.
113 DynamicArray<real> weights; ///< Weights for each node. Size = numNodes * weightsPerNode.
114
115#if MOCHI_LANGUAGE_CPP20
116 bool operator==(SkinningData const& other) const = default;
117 bool operator!=(SkinningData const& other) const = default;
118#endif
119
125};
126
127/**
128 * @brief A non-owning view of the skinning data for a Mochi mesh.
129 *
130 * @see SkinningData
131 */
133 SkinningDataView() = default;
134
135 /**
136 * @brief Implicit conversion from @ref SkinningData.
137 *
138 * @param[in] src Source data.
139 */
140 SkinningDataView(SkinningData const& src);
141
142 int weightsPerNode = 0; ///< Number of weights and indices per node being skinned.
143 Span<int const> indices; ///< Indices for each node. Size = numNodes * weightsPerNode.
144 Span<real const> weights; ///< Weights for each node. Size = numNodes * weightsPerNode.
145
146#if MOCHI_LANGUAGE_CPP20
147 bool operator==(SkinningDataView const& other) const = default;
148 bool operator!=(SkinningDataView const& other) const = default;
149#endif
150};
151
152/**
153 * @brief Mesh data for a Mochi actor or model file.
154 *
155 * @see MeshDataView
156 */
157struct MeshData {
158 MeshData() = default; ///< Default constructor
159
160 /**
161 * @brief Copy from @ref MeshDataView.
162 *
163 * @param[in] src Source data.
164 */
165 explicit MeshData(MeshDataView const& src);
166
167 /**
168 * @brief Number of nodes (vertices) per element.
169 *
170 * @note 2 for polyline mesh, 3 for triangle mesh, 4 for tetrahedral mesh
171 */
173
174 /**
175 * @brief Flat array of node coordinate values [m].
176 *
177 * @note Size must be a multiple of @ref kMeshDataSpaceDim.
178 */
180
181 /**
182 * @brief Flat array of node indices forming the elements.
183 *
184 * @note Size must be a multiple of @ref nodesPerElement.
185 */
187
188 /** @brief Optional skinning */
189 std::optional<SkinningData> skinning;
190
191 /** @brief Return the number of nodes */
192 int GetNumNodes() const;
193
194 /** @brief Return the number of elements */
195 int GetNumElements() const;
196
197 /** @brief Return true if the mesh is empty. */
198 [[nodiscard]] bool IsEmpty() const;
199
200#if MOCHI_LANGUAGE_CPP20
201 bool operator==(MeshData const& other) const = default;
202 bool operator!=(MeshData const& other) const = default;
203#endif
204
211};
212
213/**
214 * @brief A non-owning view of the mesh data for a Mochi actor or model file.
215 *
216 * @see MeshData
217 */
219 MeshDataView() = default;
220
221 /**
222 * @brief Implicit conversion from @ref MeshData.
223 *
224 * @param[in] src Source data.
225 */
226 MeshDataView(MeshData const& src);
227
228 /**
229 * @brief Number of nodes (vertices) per element.
230 *
231 * @note 2 for polyline mesh, 3 for triangle mesh, 4 for tetrahedral mesh
232 */
234
235 /**
236 * @brief Flat array of node coordinate values [m].
237 *
238 * @note Size must be a multiple of @ref kMeshDataSpaceDim.
239 */
241
242 /**
243 * @brief Flat array of node indices forming the elements.
244 *
245 * @note Size must be a multiple of @ref nodesPerElement.
246 */
248
249 /** @brief Optional skinning */
250 std::optional<SkinningDataView> skinning;
251
252 /** @brief Return the number of nodes */
253 int GetNumNodes() const;
254
255 /** @brief Return the number of elements */
256 int GetNumElements() const;
257
258 /** @brief Return true if the mesh is empty. */
259 [[nodiscard]] bool IsEmpty() const;
260
261#if MOCHI_LANGUAGE_CPP20
262 bool operator==(MeshDataView const& other) const = default;
263 bool operator!=(MeshDataView const& other) const = default;
264#endif
265};
266
267} // namespace superdex
268
269#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
A non-owning view of the data blending data for one source shape within a soft skinned mesh.
Definition mesh_data.h:76
bool operator!=(BlendingDataView const &other) const =default
Span< int const > indices
Indices for blending. Size = numNodes * 2.
Definition mesh_data.h:87
Span< real const > weights
Weights for blending Size = numNodes * 2.
Definition mesh_data.h:88
bool operator==(BlendingDataView const &other) const =default
std::string_view sourceShape
Name of the soft source shape.
Definition mesh_data.h:86
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:54
bool operator!=(BlendingData const &other) const =default
BlendingData()=default
Default constructor.
bool operator==(BlendingData const &other) const =default
DynamicArray< int > indices
Indices for blending. Size = numNodes * 2.
Definition mesh_data.h:55
DynamicArray< real > weights
Weights for blending Size = numNodes * 2.
Definition mesh_data.h:56
A non-owning view of the mesh data for a Mochi actor or model file.
Definition mesh_data.h:218
Span< int const > connectivity
Flat array of node indices forming the elements.
Definition mesh_data.h:247
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:233
bool IsEmpty() const
Return true if the mesh is empty.
std::optional< SkinningDataView > skinning
Optional skinning.
Definition mesh_data.h:250
Span< real const > coordinates
Flat array of node coordinate values [m].
Definition mesh_data.h:240
Mesh data for a Mochi actor or model file.
Definition mesh_data.h:157
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:172
DynamicArray< real > coordinates
Flat array of node coordinate values [m].
Definition mesh_data.h:179
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:186
int GetNumElements() const
Return the number of elements.
std::optional< SkinningData > skinning
Optional skinning.
Definition mesh_data.h:189
A non-owning view of the skinning data for a Mochi mesh.
Definition mesh_data.h:132
int weightsPerNode
Number of weights and indices per node being skinned.
Definition mesh_data.h:142
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:143
Span< real const > weights
Weights for each node. Size = numNodes * weightsPerNode.
Definition mesh_data.h:144
Skinning data for a Mochi mesh.
Definition mesh_data.h:101
bool operator==(SkinningData const &other) const =default
int weightsPerNode
Number of weights and indices per node being skinned.
Definition mesh_data.h:111
DynamicArray< real > weights
Weights for each node. Size = numNodes * weightsPerNode.
Definition mesh_data.h:113
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:112