Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
polygon_data.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <momentum/math/types.h>
11
12#include <span>
13
14#include <string>
15#include <vector>
16
17namespace momentum {
18
19// Structure for holding arbitrary polygon data. We will read the data as-is from the
20// FBX file and then triangulate at the end for momentum. Doing it this way allows us
21// to split up the functionality (triangulating while you read complicates handling
22// texture coordinates for example).
24 // We will pack polygons in an array like this:
25 // The indices array will contain all the polygons indices packed back-to-back.
26 // 1 2 3 4 2 3 4 6 ...
27 // The offsets array will include an offset for the start and end of each polygon.
28 // 0 4 8 ...
29 // The advantage of doing it this way is that we have random access into the
30 // polygons. The disadvantage (compared to just providing an array of vertex counts)
31 // is that the offset array should always have one more than the number of polygons,
32 // which is a little confusing.
33 std::vector<uint32_t> indices;
34 std::vector<uint32_t> offsets;
35
36 // The texture coordinate indices for each face.
37 // Uses the same offsets array as the indices array.
38 // Note that this is allowed to be empty, but if not empty it
39 // must be the same size as the indices array.
40 std::vector<uint32_t> textureIndices;
41
43
44 // If there's a problem with the mesh, returns an error message.
45 // If everything is kosher, returns an empty string.
46 // This function is used in a few places when reading the mesh from
47 // disk to make sure it's valid.
48 [[nodiscard]] std::string errorMessage(size_t numVertices) const;
49
50 // Similar to errorMessage, but the issue is not severe enough to terminate.
51 [[nodiscard]] std::string warnMessage(size_t numTexVertices) const;
52
53 [[nodiscard]] size_t numPolygons() const;
54};
55
56std::vector<Eigen::Vector3i> triangulate(
57 std::span<const uint32_t> indices,
58 std::span<const uint32_t> offsets);
59
60} // namespace momentum
std::vector< Eigen::Vector3i > triangulate(std::span< const uint32_t > indices, std::span< const uint32_t > offsets)
std::string errorMessage(size_t numVertices) const
std::vector< uint32_t > offsets
std::vector< uint32_t > indices
std::vector< uint32_t > textureIndices
std::string warnMessage(size_t numTexVertices) const
size_t numPolygons() const