Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::MeshT< T > Struct Template Reference

A generic mesh representation with support for vertices, faces, lines, and texture coordinates. More...

#include <mesh.h>

Public Member Functions

void updateNormals ()
 Compute vertex normals by averaging connected face normals.
template<typename T2>
MeshT< T2 > cast () const
 Cast the mesh to a different scalar type.
void reset ()
 Reset the mesh by clearing all data.

Public Attributes

std::vector< Eigen::Vector3< T > > vertices
 List of mesh vertices in 3D space.
std::vector< Eigen::Vector3< T > > normals
 List of vertex normals (same size as vertices when computed).
std::vector< Eigen::Vector3i > faces
 List of triangular faces defined by vertex indices.
std::vector< std::vector< int32_t > > lines
 List of polylines defined by vertex indices Each inner vector represents a single polyline.
std::vector< Eigen::Vector3b > colors
 List of per-vertex RGB colors (0-255 for each channel).
std::vector< T > confidence
 List of per-vertex confidence values Higher values typically indicate higher confidence in the vertex position.
std::vector< Eigen::Vector2f > texcoords
 List of texture coordinates (UV coordinates).
std::vector< Eigen::Vector3i > texcoord_faces
 List of texture coordinate indices per face Maps each face to its corresponding texture coordinates.
std::vector< std::vector< int32_t > > texcoord_lines
 List of texture coordinate indices per line Maps each line to its corresponding texture coordinates.
std::vector< uint32_t > polyFaces
 Packed polygon face vertex indices (all polygons concatenated back-to-back).
std::vector< uint32_t > polyFaceSizes
 Number of vertices in each polygon face.
std::vector< uint32_t > polyTexcoordFaces
 Packed polygon face texture coordinate indices (same layout as polyFaces).

Detailed Description

template<typename T>
struct momentum::MeshT< T >

A generic mesh representation with support for vertices, faces, lines, and texture coordinates.

Template Parameters
TThe scalar type used for vertex coordinates and confidence values (typically float or double)

Definition at line 20 of file mesh.h.

Member Function Documentation

◆ cast()

template<typename T>
template<typename T2>
template MeshT< double > momentum::MeshT< T >::cast< double > ( ) const
nodiscard

Cast the mesh to a different scalar type.

This method creates a new mesh with all numeric data converted to the target type. Vertex positions, normals, and confidence values are cast to the new type. Non-numeric data like faces and lines remain unchanged.

Template Parameters
T2The target scalar type
Returns
A new mesh with the target scalar type

Definition at line 65 of file mesh.cpp.

References momentum::castVectors(), colors, confidence, faces, lines, normals, polyFaces, polyFaceSizes, polyTexcoordFaces, texcoord_faces, texcoord_lines, texcoords, and vertices.

◆ reset()

template<typename T>
void momentum::MeshT< T >::reset ( )

Reset the mesh by clearing all data.

This method clears all vectors, effectively resetting the mesh to an empty state.

Definition at line 83 of file mesh.cpp.

References colors, confidence, faces, lines, normals, polyFaces, polyFaceSizes, polyTexcoordFaces, texcoord_faces, texcoord_lines, texcoords, and vertices.

◆ updateNormals()

template<typename T>
void momentum::MeshT< T >::updateNormals ( )

Compute vertex normals by averaging connected face normals.

This method calculates normals for each vertex by averaging the normals of all connected faces. The resulting normals are normalized to unit length. If a vertex is part of a degenerate face (e.g., colinear vertices), that face will not contribute to the vertex normal.

Definition at line 17 of file mesh.cpp.

References momentum::cross(), faces, momentum::IsNanNoOpt(), momentum::normal(), normals, and vertices.

Referenced by momentum::generateBoxMesh(), momentum::generateCylinderMesh(), momentum::generateSphereMesh(), and momentum::loadObjMesh().

Member Data Documentation

◆ colors

template<typename T>
std::vector<Eigen::Vector3b> momentum::MeshT< T >::colors

List of per-vertex RGB colors (0-255 for each channel).

Definition at line 35 of file mesh.h.

Referenced by cast(), momentum::loadMeshFromUsd(), momentum::logMesh(), reset(), momentum::saveMeshToUsd(), and momentum::splitMeshByTextureRegion().

◆ confidence

template<typename T>
std::vector<T> momentum::MeshT< T >::confidence

List of per-vertex confidence values Higher values typically indicate higher confidence in the vertex position.

Definition at line 39 of file mesh.h.

Referenced by cast(), momentum::loadMeshFromUsd(), reset(), momentum::saveMeshToUsd(), and momentum::splitMeshByTextureRegion().

◆ faces

◆ lines

template<typename T>
std::vector<std::vector<int32_t> > momentum::MeshT< T >::lines

List of polylines defined by vertex indices Each inner vector represents a single polyline.

Definition at line 32 of file mesh.h.

Referenced by cast(), and reset().

◆ normals

template<typename T>
std::vector<Eigen::Vector3<T> > momentum::MeshT< T >::normals

List of vertex normals (same size as vertices when computed).

Definition at line 25 of file mesh.h.

Referenced by momentum::applySSD(), cast(), momentum::loadMeshFromUsd(), momentum::logMesh(), reset(), momentum::saveMeshToUsd(), momentum::splitMeshByTextureRegion(), and updateNormals().

◆ polyFaces

template<typename T>
std::vector<uint32_t> momentum::MeshT< T >::polyFaces

Packed polygon face vertex indices (all polygons concatenated back-to-back).

For example, a quad followed by a triangle would be: [v0, v1, v2, v3, v4, v5, v6]. This is an optional, redundant representation — the triangulated faces field is always required and used by all downstream code. Polygon data preserves the original topology (quads, n-gons) from source files like FBX.

Definition at line 67 of file mesh.h.

Referenced by cast(), momentum::polysToVertices(), reset(), momentum::verticesToPolys(), momentum::fbx_internal::writePolygonsToFbxMesh(), and momentum::fbx_internal::writeTextureUVIndicesToFbxMesh().

◆ polyFaceSizes

template<typename T>
std::vector<uint32_t> momentum::MeshT< T >::polyFaceSizes

Number of vertices in each polygon face.

For example, [4, 3] means the first polygon is a quad, the second is a triangle. May be empty if polygon data is not available; see polyFaces.

Definition at line 73 of file mesh.h.

Referenced by cast(), momentum::polysToVertices(), momentum::reduceMeshByPolys(), reset(), momentum::verticesToPolys(), momentum::fbx_internal::writePolygonsToFbxMesh(), and momentum::fbx_internal::writeTextureUVIndicesToFbxMesh().

◆ polyTexcoordFaces

template<typename T>
std::vector<uint32_t> momentum::MeshT< T >::polyTexcoordFaces

Packed polygon face texture coordinate indices (same layout as polyFaces).

Uses the same polyFaceSizes array — polygon sizes are identical for geometry and texcoords. May be empty if texture coordinates are not available; see polyFaces.

Definition at line 79 of file mesh.h.

Referenced by cast(), reset(), and momentum::fbx_internal::writeTextureUVIndicesToFbxMesh().

◆ texcoord_faces

template<typename T>
std::vector<Eigen::Vector3i> momentum::MeshT< T >::texcoord_faces

List of texture coordinate indices per face Maps each face to its corresponding texture coordinates.

Definition at line 55 of file mesh.h.

Referenced by cast(), momentum::classifyTrianglesByTexture(), reset(), momentum::splitMeshByTextureRegion(), and momentum::fbx_internal::writeTextureUVIndicesToFbxMesh().

◆ texcoord_lines

template<typename T>
std::vector<std::vector<int32_t> > momentum::MeshT< T >::texcoord_lines

List of texture coordinate indices per line Maps each line to its corresponding texture coordinates.

Definition at line 59 of file mesh.h.

Referenced by cast(), and reset().

◆ texcoords

template<typename T>
std::vector<Eigen::Vector2f> momentum::MeshT< T >::texcoords

List of texture coordinates (UV coordinates).

The texture coordinates are format-agnostic, and it's the user's responsibility to ensure their consistent use.

For GLTF, Momentum stores and saves the texture coordinates as they are represented by the underlying GLTF parser. When dealing with FBX, the Y-axis is flipped. This distinction is crucial to understand when working with different formats.

Definition at line 51 of file mesh.h.

Referenced by cast(), momentum::classifyTrianglesByTexture(), reset(), and momentum::splitMeshByTextureRegion().

◆ vertices


The documentation for this struct was generated from the following files: