pymomentum-cpu 0.0.0__cp312-cp312-manylinux_2_39_x86_64.whl → 0.1.77.post30__cp312-cp312-manylinux_2_39_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pymomentum-cpu might be problematic. Click here for more details.

Files changed (85) hide show
  1. include/axel/DualContouring.h +79 -0
  2. include/axel/SignedDistanceField.h +17 -6
  3. include/axel/math/MeshHoleFilling.h +19 -0
  4. include/momentum/character/fwd.h +19 -0
  5. include/momentum/character/mesh_state.h +71 -0
  6. include/momentum/character_sequence_solver/model_parameters_sequence_error_function.h +4 -1
  7. include/momentum/character_sequence_solver/multipose_solver.h +2 -0
  8. include/momentum/character_sequence_solver/multipose_solver_function.h +3 -1
  9. include/momentum/character_sequence_solver/sequence_error_function.h +10 -1
  10. include/momentum/character_sequence_solver/sequence_solver.h +4 -4
  11. include/momentum/character_sequence_solver/sequence_solver_function.h +16 -8
  12. include/momentum/character_sequence_solver/state_sequence_error_function.h +4 -1
  13. include/momentum/character_sequence_solver/vertex_sequence_error_function.h +4 -1
  14. include/momentum/character_solver/collision_error_function.h +6 -2
  15. include/momentum/character_solver/collision_error_function_stateless.h +6 -2
  16. include/momentum/character_solver/constraint_error_function-inl.h +4 -1
  17. include/momentum/character_solver/constraint_error_function.h +9 -2
  18. include/momentum/character_solver/distance_error_function.h +4 -1
  19. include/momentum/character_solver/gauss_newton_solver_qr.h +2 -0
  20. include/momentum/character_solver/limit_error_function.h +6 -2
  21. include/momentum/character_solver/model_parameters_error_function.h +4 -1
  22. include/momentum/character_solver/point_triangle_vertex_error_function.h +15 -14
  23. include/momentum/character_solver/pose_prior_error_function.h +6 -2
  24. include/momentum/character_solver/projection_error_function.h +4 -1
  25. include/momentum/character_solver/simd_collision_error_function.h +6 -2
  26. include/momentum/character_solver/simd_normal_error_function.h +7 -1
  27. include/momentum/character_solver/simd_plane_error_function.h +12 -2
  28. include/momentum/character_solver/simd_position_error_function.h +12 -2
  29. include/momentum/character_solver/skeleton_error_function.h +19 -4
  30. include/momentum/character_solver/skeleton_solver_function.h +27 -5
  31. include/momentum/character_solver/skinned_locator_error_function.h +6 -3
  32. include/momentum/character_solver/skinned_locator_triangle_error_function.h +11 -3
  33. include/momentum/character_solver/state_error_function.h +6 -2
  34. include/momentum/character_solver/trust_region_qr.h +2 -0
  35. include/momentum/character_solver/vertex_error_function.h +15 -14
  36. include/momentum/character_solver/vertex_projection_error_function.h +11 -3
  37. include/momentum/character_solver/vertex_vertex_distance_error_function.h +11 -3
  38. include/momentum/diff_ik/fully_differentiable_orientation_error_function.h +6 -1
  39. include/momentum/diff_ik/fully_differentiable_position_error_function.h +6 -1
  40. include/momentum/diff_ik/union_error_function.h +6 -2
  41. include/momentum/io/gltf/gltf_builder.h +1 -4
  42. include/momentum/io/gltf/gltf_io.h +16 -4
  43. lib/libarrow.a +0 -0
  44. lib/libarrow_bundled_dependencies.a +0 -0
  45. lib/librerun_sdk.a +0 -0
  46. lib64/cmake/momentum/momentum-config.cmake +1 -1
  47. lib64/cmake/momentum/momentumTargets-release.cmake +0 -10
  48. lib64/cmake/momentum/momentumTargets.cmake +2 -70
  49. lib64/libaxel.a +0 -0
  50. lib64/libmomentum_app_utils.a +0 -0
  51. lib64/libmomentum_character.a +0 -0
  52. lib64/libmomentum_character_sequence_solver.a +0 -0
  53. lib64/libmomentum_character_solver.a +0 -0
  54. lib64/libmomentum_common.a +0 -0
  55. lib64/libmomentum_diff_ik.a +0 -0
  56. lib64/libmomentum_io.a +0 -0
  57. lib64/libmomentum_io_common.a +0 -0
  58. lib64/libmomentum_io_fbx.a +0 -0
  59. lib64/libmomentum_io_gltf.a +0 -0
  60. lib64/libmomentum_io_legacy_json.a +0 -0
  61. lib64/libmomentum_io_marker.a +0 -0
  62. lib64/libmomentum_io_motion.a +0 -0
  63. lib64/libmomentum_io_shape.a +0 -0
  64. lib64/libmomentum_io_skeleton.a +0 -0
  65. lib64/libmomentum_io_urdf.a +0 -0
  66. lib64/libmomentum_marker_tracker.a +0 -0
  67. lib64/libmomentum_math.a +0 -0
  68. lib64/libmomentum_online_qr.a +0 -0
  69. lib64/libmomentum_process_markers.a +0 -0
  70. lib64/libmomentum_rerun.a +0 -0
  71. lib64/libmomentum_simd_constraints.a +0 -0
  72. lib64/libmomentum_simd_generalized_loss.a +0 -0
  73. lib64/libmomentum_skeleton.a +0 -0
  74. lib64/libmomentum_solver.a +0 -0
  75. pymomentum/axel.cpython-312-x86_64-linux-gnu.so +0 -0
  76. pymomentum/geometry.cpython-312-x86_64-linux-gnu.so +0 -0
  77. pymomentum/marker_tracking.cpython-312-x86_64-linux-gnu.so +0 -0
  78. pymomentum/solver.cpython-312-x86_64-linux-gnu.so +0 -0
  79. pymomentum/solver2.cpython-312-x86_64-linux-gnu.so +0 -0
  80. {pymomentum_cpu-0.0.0.dist-info → pymomentum_cpu-0.1.77.post30.dist-info}/METADATA +3 -4
  81. {pymomentum_cpu-0.0.0.dist-info → pymomentum_cpu-0.1.77.post30.dist-info}/RECORD +83 -83
  82. lib64/libmomentum_rasterizer.a +0 -0
  83. pymomentum/renderer.cpython-312-x86_64-linux-gnu.so +0 -0
  84. {pymomentum_cpu-0.0.0.dist-info → pymomentum_cpu-0.1.77.post30.dist-info}/WHEEL +0 -0
  85. {pymomentum_cpu-0.0.0.dist-info → pymomentum_cpu-0.1.77.post30.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,79 @@
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 <array>
11
+ #include <unordered_map>
12
+ #include <vector>
13
+
14
+ #include <Eigen/Core>
15
+ #include <Eigen/Dense>
16
+ #include <gsl/span>
17
+
18
+ #include "axel/BoundingBox.h"
19
+ #include "axel/SignedDistanceField.h"
20
+ #include "axel/common/Types.h"
21
+
22
+ namespace axel {
23
+
24
+ /**
25
+ * Result of dual contouring operation.
26
+ * Dual contouring naturally produces quads, so this always contains quads.
27
+ * Use triangulateQuads() to convert to triangles if needed.
28
+ */
29
+ template <typename S>
30
+ struct DualContouringResult {
31
+ using Scalar = S;
32
+
33
+ /// Generated vertices
34
+ std::vector<Eigen::Vector3<S>> vertices;
35
+
36
+ /// Generated quads (dual contouring naturally produces quads)
37
+ std::vector<Eigen::Vector4i> quads;
38
+
39
+ /// Success flag
40
+ bool success = false;
41
+
42
+ /// Number of cells processed
43
+ size_t processedCells = 0;
44
+
45
+ /// Number of vertices generated
46
+ size_t generatedVertices = 0;
47
+ };
48
+
49
+ /**
50
+ * Extract an isosurface from a signed distance field using dual contouring.
51
+ *
52
+ * Dual contouring places vertices inside grid cells (rather than on edges like marching cubes)
53
+ * and uses both function values and gradients to determine optimal vertex placement.
54
+ * This results in better preservation of sharp features and corners compared to marching cubes.
55
+ *
56
+ * The algorithm works by:
57
+ * 1. Finding all cells that intersect the isosurface (sign changes across cell corners)
58
+ * 2. Placing one vertex at each intersecting cell, positioned on the surface using gradient descent
59
+ * 3. Generating quads for each edge crossing that connects 4 adjacent cells
60
+ *
61
+ * @param sdf The signed distance field to extract from
62
+ * @param isovalue The isovalue to extract (typically 0.0 for zero level set)
63
+ * @return Result containing extracted mesh
64
+ */
65
+ template <typename ScalarType>
66
+ DualContouringResult<ScalarType> dualContouring(
67
+ const SignedDistanceField<ScalarType>& sdf,
68
+ ScalarType isovalue = ScalarType{0.0});
69
+
70
+ /**
71
+ * Triangulate a quad mesh into triangles.
72
+ * Each quad is split into two triangles using the diagonal (0,2).
73
+ *
74
+ * @param quads Vector of quads to triangulate
75
+ * @return Vector of triangles
76
+ */
77
+ std::vector<Eigen::Vector3i> triangulateQuads(const std::vector<Eigen::Vector4i>& quads);
78
+
79
+ } // namespace axel
@@ -89,7 +89,8 @@ class SignedDistanceField {
89
89
  * @param position 3D world-space position to query
90
90
  * @return Interpolated signed distance value
91
91
  */
92
- [[nodiscard]] Scalar sample(const Vector3& position) const;
92
+ template <typename InputScalar = Scalar>
93
+ [[nodiscard]] InputScalar sample(const Eigen::Vector3<InputScalar>& position) const;
93
94
 
94
95
  /**
95
96
  * Sample the SDF gradient at a continuous 3D position using analytical gradients
@@ -98,7 +99,9 @@ class SignedDistanceField {
98
99
  * @param position 3D world-space position to query
99
100
  * @return Gradient vector at the given position
100
101
  */
101
- [[nodiscard]] Vector3 gradient(const Vector3& position) const;
102
+ template <typename InputScalar = Scalar>
103
+ [[nodiscard]] Eigen::Vector3<InputScalar> gradient(
104
+ const Eigen::Vector3<InputScalar>& position) const;
102
105
 
103
106
  /**
104
107
  * Sample both the SDF value and gradient at a continuous 3D position using
@@ -108,7 +111,9 @@ class SignedDistanceField {
108
111
  * @param position 3D world-space position to query
109
112
  * @return Pair of (value, gradient) at the given position
110
113
  */
111
- [[nodiscard]] std::pair<Scalar, Vector3> sampleWithGradient(const Vector3& position) const;
114
+ template <typename InputScalar = Scalar>
115
+ [[nodiscard]] std::pair<InputScalar, Eigen::Vector3<InputScalar>> sampleWithGradient(
116
+ const Eigen::Vector3<InputScalar>& position) const;
112
117
 
113
118
  /**
114
119
  * Convert a 3D world-space position to continuous grid coordinates.
@@ -116,7 +121,9 @@ class SignedDistanceField {
116
121
  * @param position 3D world-space position
117
122
  * @return Continuous grid coordinates (may be fractional)
118
123
  */
119
- [[nodiscard]] Vector3 worldToGrid(const Vector3& position) const;
124
+ template <typename InputScalar = Scalar>
125
+ [[nodiscard]] Eigen::Vector3<InputScalar> worldToGrid(
126
+ const Eigen::Vector3<InputScalar>& position) const;
120
127
 
121
128
  /**
122
129
  * Convert continuous grid coordinates to 3D world-space position.
@@ -124,7 +131,9 @@ class SignedDistanceField {
124
131
  * @param gridPos Continuous grid coordinates
125
132
  * @return 3D world-space position
126
133
  */
127
- [[nodiscard]] Vector3 gridToWorld(const Vector3& gridPos) const;
134
+ template <typename InputScalar = Scalar>
135
+ [[nodiscard]] Eigen::Vector3<InputScalar> gridToWorld(
136
+ const Eigen::Vector3<InputScalar>& gridPos) const;
128
137
 
129
138
  /**
130
139
  * Get the world-space position of a grid cell center given discrete indices.
@@ -220,7 +229,9 @@ class SignedDistanceField {
220
229
  * @param gridPos Input grid coordinates
221
230
  * @return Clamped grid coordinates
222
231
  */
223
- [[nodiscard]] Vector3 clampToGrid(const Vector3& gridPos) const;
232
+ template <typename InputScalar = Scalar>
233
+ [[nodiscard]] Eigen::Vector3<InputScalar> clampToGrid(
234
+ const Eigen::Vector3<InputScalar>& gridPos) const;
224
235
 
225
236
  BoundingBoxType bounds_;
226
237
  Eigen::Vector3<Index> resolution_;
@@ -95,4 +95,23 @@ fillMeshHolesComplete(
95
95
  gsl::span<const Eigen::Vector3<ScalarType>> vertices,
96
96
  gsl::span<const Eigen::Vector3i> triangles);
97
97
 
98
+ /**
99
+ * Apply Laplacian smoothing to mesh vertices with optional masking.
100
+ *
101
+ * @param vertices Input mesh vertices
102
+ * @param faces Mesh faces (triangles or quads)
103
+ * @param vertex_mask Optional mask to specify which vertices to smooth (if empty, all vertices are
104
+ * smoothed)
105
+ * @param iterations Number of smoothing iterations
106
+ * @param step Smoothing step size (0-1)
107
+ * @return Smoothed vertices
108
+ */
109
+ template <typename ScalarType, typename FaceType>
110
+ std::vector<Eigen::Vector3<ScalarType>> smoothMeshLaplacian(
111
+ gsl::span<const Eigen::Vector3<ScalarType>> vertices,
112
+ gsl::span<const FaceType> faces,
113
+ const std::vector<bool>& vertex_mask = {},
114
+ Index iterations = 1,
115
+ ScalarType step = ScalarType{0.5});
116
+
98
117
  } // namespace axel
@@ -221,6 +221,25 @@ using SkeletonStated_const_p = ::std::shared_ptr<const SkeletonStated>;
221
221
  using SkeletonStated_const_u = ::std::unique_ptr<const SkeletonStated>;
222
222
  using SkeletonStated_const_w = ::std::weak_ptr<const SkeletonStated>;
223
223
 
224
+ template <typename T>
225
+ struct MeshStateT;
226
+ using MeshState = MeshStateT<float>;
227
+ using MeshStated = MeshStateT<double>;
228
+
229
+ using MeshState_p = ::std::shared_ptr<MeshState>;
230
+ using MeshState_u = ::std::unique_ptr<MeshState>;
231
+ using MeshState_w = ::std::weak_ptr<MeshState>;
232
+ using MeshState_const_p = ::std::shared_ptr<const MeshState>;
233
+ using MeshState_const_u = ::std::unique_ptr<const MeshState>;
234
+ using MeshState_const_w = ::std::weak_ptr<const MeshState>;
235
+
236
+ using MeshStated_p = ::std::shared_ptr<MeshStated>;
237
+ using MeshStated_u = ::std::unique_ptr<MeshStated>;
238
+ using MeshStated_w = ::std::weak_ptr<MeshStated>;
239
+ using MeshStated_const_p = ::std::shared_ptr<const MeshStated>;
240
+ using MeshStated_const_u = ::std::unique_ptr<const MeshStated>;
241
+ using MeshStated_const_w = ::std::weak_ptr<const MeshStated>;
242
+
224
243
  template <typename T>
225
244
  struct TaperedCapsuleT;
226
245
  using TaperedCapsule = TaperedCapsuleT<float>;
@@ -0,0 +1,71 @@
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/character/fwd.h>
11
+ #include <momentum/character/types.h>
12
+ #include <momentum/math/mesh.h>
13
+ #include <momentum/math/types.h>
14
+
15
+ namespace momentum {
16
+
17
+ /// Represents the complete state of a model's mesh
18
+ ///
19
+ /// Stores the mesh in its various states throughout the deformation pipeline:
20
+ /// - neutralMesh: Base mesh before any deformations
21
+ /// - restMesh: Mesh after blend shapes/expressions are applied
22
+ /// - posedMesh: Final mesh after skinning is applied
23
+ template <typename T>
24
+ struct MeshStateT {
25
+ std::unique_ptr<MeshT<T>>
26
+ neutralMesh_; // Rest mesh without facial expression basis,
27
+ // used to restore the neutral shape after facial expressions are applied.
28
+ // Not used with there is a shape basis.
29
+ std::unique_ptr<MeshT<T>> restMesh_; // The rest positions of the mesh after shape basis
30
+ // (and potentially facial expression) has been applied
31
+ std::unique_ptr<MeshT<T>>
32
+ posedMesh_; // The posed mesh after the skeleton transforms have been applied.
33
+
34
+ /// Creates an empty mesh state
35
+ MeshStateT() noexcept = default;
36
+ MeshStateT(
37
+ const ModelParametersT<T>& parameters,
38
+ const SkeletonStateT<T>& state,
39
+ const Character& character) noexcept;
40
+ ~MeshStateT() noexcept;
41
+
42
+ /// Copy constructor
43
+ MeshStateT(const MeshStateT& other);
44
+
45
+ /// Copy assignment operator
46
+ MeshStateT& operator=(const MeshStateT& other);
47
+
48
+ /// Move constructor
49
+ MeshStateT(MeshStateT&& other) noexcept = default;
50
+
51
+ /// Move assignment operator
52
+ MeshStateT& operator=(MeshStateT&& other) noexcept = default;
53
+
54
+ /// Updates the mesh state based on model parameters and skeleton state
55
+ ///
56
+ /// This applies the full deformation pipeline:
57
+ /// 1. Apply blend shapes to create rest mesh
58
+ /// 2. Apply face expression blend shapes
59
+ /// 3. Update normals
60
+ /// 4. Apply skinning to create posed mesh
61
+ ///
62
+ /// @param parameters Model parameters containing blend weights
63
+ /// @param state Current skeleton state for skinning
64
+ /// @param character Character containing mesh, blend shapes, and skinning data
65
+ void update(
66
+ const ModelParametersT<T>& parameters,
67
+ const SkeletonStateT<T>& state,
68
+ const Character& character);
69
+ };
70
+
71
+ } // namespace momentum
@@ -25,10 +25,12 @@ class ModelParametersSequenceErrorFunctionT : public SequenceErrorFunctionT<T> {
25
25
 
26
26
  double getError(
27
27
  gsl::span<const ModelParametersT<T>> modelParameters,
28
- gsl::span<const SkeletonStateT<T>> skelStates) const final;
28
+ gsl::span<const SkeletonStateT<T>> skelStates,
29
+ gsl::span<const MeshStateT<T>> meshStates) const final;
29
30
  double getGradient(
30
31
  gsl::span<const ModelParametersT<T>> modelParameters,
31
32
  gsl::span<const SkeletonStateT<T>> skelStates,
33
+ gsl::span<const MeshStateT<T>> meshStates,
32
34
  Eigen::Ref<Eigen::VectorX<T>> gradient) const final;
33
35
 
34
36
  // modelParameters: [numFrames() * parameterTransform] parameter vector
@@ -38,6 +40,7 @@ class ModelParametersSequenceErrorFunctionT : public SequenceErrorFunctionT<T> {
38
40
  double getJacobian(
39
41
  gsl::span<const ModelParametersT<T>> modelParameters,
40
42
  gsl::span<const SkeletonStateT<T>> skelStates,
43
+ gsl::span<const MeshStateT<T>> meshStates,
41
44
  Eigen::Ref<Eigen::MatrixX<T>> jacobian,
42
45
  Eigen::Ref<Eigen::VectorX<T>> residual,
43
46
  int& usedRows) const final;
@@ -30,6 +30,7 @@ template <typename T>
30
30
  class MultiposeSolverT : public SolverT<T> {
31
31
  public:
32
32
  MultiposeSolverT(const SolverOptions& options, MultiposeSolverFunctionT<T>* function);
33
+ ~MultiposeSolverT() override;
33
34
 
34
35
  [[nodiscard]] std::string_view getName() const override;
35
36
 
@@ -56,6 +57,7 @@ class MultiposeSolverT : public SolverT<T> {
56
57
  private:
57
58
  Eigen::MatrixX<T> jacobianBlock_;
58
59
  Eigen::VectorX<T> residualBlock_;
60
+ std::unique_ptr<MeshStateT<T>> meshState_;
59
61
 
60
62
  float regularization_;
61
63
  };
@@ -24,6 +24,7 @@ class MultiposeSolverFunctionT : public SolverFunctionT<T> {
24
24
  const ParameterTransformT<T>* parameterTransform,
25
25
  gsl::span<const int> universal,
26
26
  size_t frames);
27
+ ~MultiposeSolverFunctionT() override;
27
28
 
28
29
  double getError(const Eigen::VectorX<T>& parameters) final;
29
30
 
@@ -62,7 +63,8 @@ class MultiposeSolverFunctionT : public SolverFunctionT<T> {
62
63
  private:
63
64
  const Skeleton* skeleton_;
64
65
  const ParameterTransformT<T>* parameterTransform_;
65
- std::vector<std::unique_ptr<SkeletonStateT<T>>> states_;
66
+ std::vector<SkeletonStateT<T>> states_;
67
+ std::vector<MeshStateT<T>> meshStates_;
66
68
  VectorX<bool> activeJointParams_;
67
69
 
68
70
  std::vector<ModelParametersT<T>> frameParameters_;
@@ -41,30 +41,39 @@ class SequenceErrorFunctionT {
41
41
  enabledParameters_ = ps;
42
42
  }
43
43
 
44
+ [[nodiscard]] virtual bool needsMesh() const {
45
+ return false;
46
+ }
47
+
44
48
  [[nodiscard]] virtual double getError(
45
49
  gsl::span<const ModelParametersT<T>> /* modelParameters */,
46
- gsl::span<const SkeletonStateT<T>> /* skelStates */) const {
50
+ gsl::span<const SkeletonStateT<T>> /* skelStates */,
51
+ gsl::span<const MeshStateT<T>> /* meshStates */) const {
47
52
  return 0.0f;
48
53
  }
49
54
 
50
55
  // Get the gradient of the error.
51
56
  // modelParameters: numFrames() array of parameter vectors
52
57
  // skelStates: [numFrames()] array of skeleton states
58
+ // meshStates: [numFrames()] array of mesh states
53
59
  // gradient: [numFrames() * parameterTransform] gradient vector
54
60
  virtual double getGradient(
55
61
  gsl::span<const ModelParametersT<T>> /* modelParameters */,
56
62
  gsl::span<const SkeletonStateT<T>> /* skelStates */,
63
+ gsl::span<const MeshStateT<T>> /* meshStates */,
57
64
  Eigen::Ref<Eigen::VectorX<T>> /* gradient */) const {
58
65
  return 0.0f;
59
66
  }
60
67
 
61
68
  // modelParameters: [numFrames() * parameterTransform] parameter vector
62
69
  // skelStates: [numFrames()] array of skeleton states
70
+ // meshStates: [numFrames()] array of mesh states
63
71
  // jacobian: [getJacobianSize()] x [numFrames() * parameterTransform] Jacobian matrix
64
72
  // residual: [getJacobianSize()] residual vector.
65
73
  virtual double getJacobian(
66
74
  gsl::span<const ModelParametersT<T>> /* modelParameters */,
67
75
  gsl::span<const SkeletonStateT<T>> /* skelStates */,
76
+ gsl::span<const MeshStateT<T>> /* meshStates */,
68
77
  Eigen::Ref<Eigen::MatrixX<T>> /* jacobian */,
69
78
  Eigen::Ref<Eigen::VectorX<T>> /* residual */,
70
79
  int& usedRows) const {
@@ -132,10 +132,10 @@ class SequenceSolverT : public SolverT<T> {
132
132
  const SequenceSolverFunctionT<T>* fn,
133
133
  size_t bandwidth);
134
134
 
135
- float regularization_;
136
- bool doLineSearch_;
137
- bool multithreaded_;
138
- bool progressBar_;
135
+ float regularization_ = 0.05f;
136
+ bool doLineSearch_ = false;
137
+ bool multithreaded_ = false;
138
+ bool progressBar_ = false;
139
139
 
140
140
  // bandwidth in frames:
141
141
  size_t bandwidth_ = 0;
@@ -24,10 +24,11 @@ template <typename T>
24
24
  class SequenceSolverFunctionT : public SolverFunctionT<T> {
25
25
  public:
26
26
  SequenceSolverFunctionT(
27
- const Skeleton* skel,
28
- const ParameterTransformT<T>* parameterTransform,
27
+ const Character& character,
28
+ const ParameterTransformT<T>& parameterTransform,
29
29
  const ParameterSet& universal,
30
30
  size_t nFrames);
31
+ ~SequenceSolverFunctionT() override;
31
32
 
32
33
  double getError(const Eigen::VectorX<T>& parameters) final;
33
34
 
@@ -46,6 +47,10 @@ class SequenceSolverFunctionT : public SolverFunctionT<T> {
46
47
  return universalParameters_;
47
48
  }
48
49
 
50
+ [[nodiscard]] bool needsMesh() const {
51
+ return needsMesh_;
52
+ }
53
+
49
54
  // Passing in the special frame index kAllFrames will add the error function to every frame; this
50
55
  // is convenient for e.g. limit errors but requires that the error function be stateless. Note:
51
56
  // you are allowed to call this in a multithreaded context but you must ensure the frame indices
@@ -78,11 +83,11 @@ class SequenceSolverFunctionT : public SolverFunctionT<T> {
78
83
 
79
84
  void setJoinedParameterVector(const Eigen::VectorX<T>& joinedParameters);
80
85
 
81
- [[nodiscard]] const Skeleton* getSkeleton() const {
82
- return skeleton_;
83
- }
86
+ [[nodiscard]] const Skeleton* getSkeleton() const;
87
+ [[nodiscard]] const Character& getCharacter() const;
88
+
84
89
  [[nodiscard]] const ParameterTransformT<T>* getParameterTransform() const {
85
- return parameterTransform_;
90
+ return &parameterTransform_;
86
91
  }
87
92
 
88
93
  [[nodiscard]] const auto& getErrorFunctions(size_t iFrame) const {
@@ -97,9 +102,10 @@ class SequenceSolverFunctionT : public SolverFunctionT<T> {
97
102
  void setFrameParametersFromJoinedParameterVector(const Eigen::VectorX<T>& parameters);
98
103
 
99
104
  private:
100
- const Skeleton* skeleton_;
101
- const ParameterTransformT<T>* parameterTransform_;
105
+ const Character& character_;
106
+ const ParameterTransformT<T>& parameterTransform_;
102
107
  std::vector<SkeletonStateT<T>> states_;
108
+ std::vector<MeshStateT<T>> meshStates_;
103
109
  VectorX<bool> activeJointParams_;
104
110
 
105
111
  std::vector<ModelParametersT<T>> frameParameters_;
@@ -120,6 +126,8 @@ class SequenceSolverFunctionT : public SolverFunctionT<T> {
120
126
  std::atomic<size_t> numTotalPerFrameErrorFunctions_ = 0;
121
127
  std::atomic<size_t> numTotalSequenceErrorFunctions_ = 0;
122
128
 
129
+ bool needsMesh_ = false;
130
+
123
131
  friend class SequenceSolverT<T>;
124
132
  };
125
133
 
@@ -29,10 +29,12 @@ class StateSequenceErrorFunctionT : public SequenceErrorFunctionT<T> {
29
29
 
30
30
  double getError(
31
31
  gsl::span<const ModelParametersT<T>> modelParameters,
32
- gsl::span<const SkeletonStateT<T>> skelStates) const final;
32
+ gsl::span<const SkeletonStateT<T>> skelStates,
33
+ gsl::span<const MeshStateT<T>> /* meshStates */) const final;
33
34
  double getGradient(
34
35
  gsl::span<const ModelParametersT<T>> modelParameters,
35
36
  gsl::span<const SkeletonStateT<T>> skelStates,
37
+ gsl::span<const MeshStateT<T>> /* meshStates */,
36
38
  Eigen::Ref<Eigen::VectorX<T>> gradient) const final;
37
39
 
38
40
  // modelParameters: [numFrames() * parameterTransform] parameter vector
@@ -42,6 +44,7 @@ class StateSequenceErrorFunctionT : public SequenceErrorFunctionT<T> {
42
44
  double getJacobian(
43
45
  gsl::span<const ModelParametersT<T>> modelParameters,
44
46
  gsl::span<const SkeletonStateT<T>> skelStates,
47
+ gsl::span<const MeshStateT<T>> /* meshStates */,
45
48
  Eigen::Ref<Eigen::MatrixX<T>> jacobian,
46
49
  Eigen::Ref<Eigen::VectorX<T>> residual,
47
50
  int& usedRows) const final;
@@ -47,10 +47,12 @@ class VertexSequenceErrorFunctionT : public SequenceErrorFunctionT<T> {
47
47
 
48
48
  double getError(
49
49
  gsl::span<const ModelParametersT<T>> modelParameters,
50
- gsl::span<const SkeletonStateT<T>> skelStates) const final;
50
+ gsl::span<const SkeletonStateT<T>> skelStates,
51
+ gsl::span<const MeshStateT<T>> meshStates) const final;
51
52
  double getGradient(
52
53
  gsl::span<const ModelParametersT<T>> modelParameters,
53
54
  gsl::span<const SkeletonStateT<T>> skelStates,
55
+ gsl::span<const MeshStateT<T>> meshStates,
54
56
  Eigen::Ref<Eigen::VectorX<T>> gradient) const final;
55
57
 
56
58
  // modelParameters: [numFrames() * parameterTransform] parameter vector
@@ -60,6 +62,7 @@ class VertexSequenceErrorFunctionT : public SequenceErrorFunctionT<T> {
60
62
  double getJacobian(
61
63
  gsl::span<const ModelParametersT<T>> modelParameters,
62
64
  gsl::span<const SkeletonStateT<T>> skelStates,
65
+ gsl::span<const MeshStateT<T>> meshStates,
63
66
  Eigen::Ref<Eigen::MatrixX<T>> jacobian,
64
67
  Eigen::Ref<Eigen::VectorX<T>> residual,
65
68
  int& usedRows) const final;
@@ -29,17 +29,21 @@ class CollisionErrorFunctionT : public SkeletonErrorFunctionT<T> {
29
29
 
30
30
  explicit CollisionErrorFunctionT(const Character& character);
31
31
 
32
- [[nodiscard]] double getError(const ModelParametersT<T>& params, const SkeletonStateT<T>& state)
33
- final;
32
+ [[nodiscard]] double getError(
33
+ const ModelParametersT<T>& params,
34
+ const SkeletonStateT<T>& state,
35
+ const MeshStateT<T>& meshState) final;
34
36
 
35
37
  double getGradient(
36
38
  const ModelParametersT<T>& params,
37
39
  const SkeletonStateT<T>& state,
40
+ const MeshStateT<T>& meshState,
38
41
  Ref<VectorX<T>> gradient) override;
39
42
 
40
43
  double getJacobian(
41
44
  const ModelParametersT<T>& /*unused*/,
42
45
  const SkeletonStateT<T>& state,
46
+ const MeshStateT<T>& meshState,
43
47
  Ref<MatrixX<T>> jacobian,
44
48
  Ref<VectorX<T>> residual,
45
49
  int& usedRows) override;
@@ -32,17 +32,21 @@ class CollisionErrorFunctionStatelessT : public SkeletonErrorFunctionT<T> {
32
32
 
33
33
  explicit CollisionErrorFunctionStatelessT(const Character& character);
34
34
 
35
- [[nodiscard]] double getError(const ModelParametersT<T>& params, const SkeletonStateT<T>& state)
36
- final;
35
+ [[nodiscard]] double getError(
36
+ const ModelParametersT<T>& params,
37
+ const SkeletonStateT<T>& state,
38
+ const MeshStateT<T>& meshState) final;
37
39
 
38
40
  double getGradient(
39
41
  const ModelParametersT<T>& params,
40
42
  const SkeletonStateT<T>& state,
43
+ const MeshStateT<T>& meshState,
41
44
  Ref<VectorX<T>> gradient) override;
42
45
 
43
46
  double getJacobian(
44
47
  const ModelParametersT<T>& /*unused*/,
45
48
  const SkeletonStateT<T>& state,
49
+ const MeshStateT<T>& meshState,
46
50
  Ref<MatrixX<T>> jacobian,
47
51
  Ref<VectorX<T>> residual,
48
52
  int& usedRows) override;
@@ -31,7 +31,8 @@ ConstraintErrorFunctionT<T, Data, FuncDim, NumVec, NumPos>::ConstraintErrorFunct
31
31
  template <typename T, class Data, size_t FuncDim, size_t NumVec, size_t NumPos>
32
32
  double ConstraintErrorFunctionT<T, Data, FuncDim, NumVec, NumPos>::getError(
33
33
  const ModelParametersT<T>& /* params */,
34
- const SkeletonStateT<T>& state) {
34
+ const SkeletonStateT<T>& state,
35
+ const MeshStateT<T>& /* meshState */) {
35
36
  MT_PROFILE_FUNCTION();
36
37
 
37
38
  // loop over all constraints and calculate the error
@@ -172,6 +173,7 @@ template <typename T, class Data, size_t FuncDim, size_t NumVec, size_t NumPos>
172
173
  double ConstraintErrorFunctionT<T, Data, FuncDim, NumVec, NumPos>::getJacobian(
173
174
  const ModelParametersT<T>& /*params*/,
174
175
  const SkeletonStateT<T>& state,
176
+ const MeshStateT<T>& /* meshState */,
175
177
  Ref<Eigen::MatrixX<T>> jacobian,
176
178
  Ref<Eigen::VectorX<T>> residual,
177
179
  int& usedRows) {
@@ -298,6 +300,7 @@ template <typename T, class Data, size_t FuncDim, size_t NumVec, size_t NumPos>
298
300
  double ConstraintErrorFunctionT<T, Data, FuncDim, NumVec, NumPos>::getGradient(
299
301
  const ModelParametersT<T>& /*unused*/,
300
302
  const SkeletonStateT<T>& state,
303
+ const MeshStateT<T>& /* meshState */,
301
304
  Ref<Eigen::VectorX<T>> gradient) {
302
305
  MT_PROFILE_FUNCTION();
303
306
 
@@ -116,22 +116,27 @@ class ConstraintErrorFunctionT : public SkeletonErrorFunctionT<T> {
116
116
  ///
117
117
  /// @param[in] params: current model parameters
118
118
  /// @param[in] state: curren global skeleton joint states computed from the model parameters
119
+ /// @param[in] meshState: current mesh state (unused by this base class)
119
120
  ///
120
121
  /// @return the error function value l
121
- [[nodiscard]] double getError(const ModelParametersT<T>& params, const SkeletonStateT<T>& state)
122
- final;
122
+ [[nodiscard]] double getError(
123
+ const ModelParametersT<T>& params,
124
+ const SkeletonStateT<T>& state,
125
+ const MeshStateT<T>& /* meshState */) final;
123
126
 
124
127
  /// The gradient of the error function: dl/dq = dl/d[f^2] * 2f * df/dv * dv/dq. It gets df/dv from
125
128
  /// the derived class, and implements the rest.
126
129
  ///
127
130
  /// @param[in] params: current model parameters
128
131
  /// @param[in] state: curren global skeleton joint states computed from the model parameters
132
+ /// @param[in] meshState: current mesh state (unused by this base class)
129
133
  /// @param[out] gradient: the gradient vector to accumulate into
130
134
  ///
131
135
  /// @return the error function value l
132
136
  double getGradient(
133
137
  const ModelParametersT<T>& params,
134
138
  const SkeletonStateT<T>& state,
139
+ const MeshStateT<T>& /* meshState */,
135
140
  Ref<VectorX<T>> gradient) final;
136
141
 
137
142
  /// For least-square problems, we assume l is the square of a vector function F. The jacobian is
@@ -142,6 +147,7 @@ class ConstraintErrorFunctionT : public SkeletonErrorFunctionT<T> {
142
147
  ///
143
148
  /// @param[in] params: current model parameters
144
149
  /// @param[in] state: curren global skeleton joint states computed from the model parameters
150
+ /// @param[in] meshState: current mesh state (unused by this base class)
145
151
  /// @param[out] jacobian: the output jacobian matrix
146
152
  /// @param[out] residual: the output function residual (ie. f scaled by the loss gradient)
147
153
  /// @param[out] usedRows: number of rows in the jacobian/residual used by this error function
@@ -150,6 +156,7 @@ class ConstraintErrorFunctionT : public SkeletonErrorFunctionT<T> {
150
156
  double getJacobian(
151
157
  const ModelParametersT<T>& params,
152
158
  const SkeletonStateT<T>& state,
159
+ const MeshStateT<T>& /* meshState */,
153
160
  Ref<MatrixX<T>> jacobian,
154
161
  Ref<VectorX<T>> residual,
155
162
  int& usedRows) final;
@@ -31,14 +31,17 @@ class DistanceErrorFunctionT : public momentum::SkeletonErrorFunctionT<T> {
31
31
 
32
32
  [[nodiscard]] double getError(
33
33
  const momentum::ModelParametersT<T>& params,
34
- const momentum::SkeletonStateT<T>& state) final;
34
+ const momentum::SkeletonStateT<T>& state,
35
+ const momentum::MeshStateT<T>& meshState) final;
35
36
  double getGradient(
36
37
  const momentum::ModelParametersT<T>& params,
37
38
  const momentum::SkeletonStateT<T>& state,
39
+ const momentum::MeshStateT<T>& meshState,
38
40
  Eigen::Ref<Eigen::VectorX<T>> gradient) final;
39
41
  double getJacobian(
40
42
  const momentum::ModelParametersT<T>& params,
41
43
  const momentum::SkeletonStateT<T>& state,
44
+ const momentum::MeshStateT<T>& meshState,
42
45
  Eigen::Ref<Eigen::MatrixX<T>> jacobian,
43
46
  Eigen::Ref<Eigen::VectorX<T>> residual,
44
47
  int& usedRows) final;
@@ -38,6 +38,7 @@ template <typename T>
38
38
  class GaussNewtonSolverQRT : public SolverT<T> {
39
39
  public:
40
40
  GaussNewtonSolverQRT(const SolverOptions& options, SkeletonSolverFunctionT<T>* solver);
41
+ ~GaussNewtonSolverQRT() override;
41
42
 
42
43
  [[nodiscard]] std::string_view getName() const override;
43
44
 
@@ -49,6 +50,7 @@ class GaussNewtonSolverQRT : public SolverT<T> {
49
50
 
50
51
  private:
51
52
  std::unique_ptr<SkeletonStateT<T>> skeletonState_;
53
+ std::unique_ptr<MeshStateT<T>> meshState_;
52
54
 
53
55
  ResizeableMatrix<T> jacobian_;
54
56
  ResizeableMatrix<T> residual_;