cgv
Loading...
Searching...
No Matches
adaptive_skinned_mesh.cxx
1#include "adaptive_skinned_mesh.h"
2#include <cgv/math/ftransform.h>
3
4namespace cgv {
5 namespace media {
6 namespace mesh {
7
8template <typename T>
9void adaptive_skinned_mesh<T>::compute_rotation_matrices(const std::vector<vec3_type>& pose, std::vector<mat3_type>& rotation_matrices)
10{
11 rotation_matrices.clear();
12 for (const auto& p : pose) {
13 auto R = rotate3s(p);
14 rotation_matrices.push_back(rotate3s(p));
15 }
16}
17
18template <typename T>
19void adaptive_skinned_mesh<T>::compute_joint_locations(const std::vector<vec3_type>& P)
20{
21 joint_locations.resize(joint_regressors.size());
22 std::fill(joint_locations.begin(), joint_locations.end(), vec3_type(0.0f));
23 for (unsigned vi = 0; vi < P.size(); ++vi) {
24 for (size_t ji = 0; ji < joint_regressors.size(); ++ji)
25 joint_locations[ji] += joint_regressors[ji][vi] * P[vi];
26 }
27}
28
29template <typename T>
31{
32 alternative_joint_regressors.resize(joint_regressors.size());
33 /*std::fill(joint_locations.begin(), joint_locations.end(), vec3_type(0.0f));
34 for (unsigned vi = 0; vi < P.size(); ++vi) {
35 for (size_t ji = 0; ji < joint_regressors.size(); ++ji)
36 joint_locations[ji] += joint_regressors[ji][vi] * P[vi];
37 }
38 */
39}
40
41template <typename T>
42std::vector<T> adaptive_skinned_mesh<T>::compute_pose_correction_vector(const std::vector<mat3_type>& rotation_matrices) const
43{
44 std::vector<T> PCs;
45 for (unsigned ji = 1; ji < rotation_matrices.size(); ++ji) {
46 mat3_type PC = rotation_matrices[ji] - cgv::math::identity3<T>();
47 PC = transpose(PC);
48 for (unsigned i = 0; i < 9; ++i)
49 PCs.push_back(PC[i]);
50 }
51 return PCs;
52}
53
54template <typename T>
55void adaptive_skinned_mesh<T>::shape_mesh(const std::vector<T>& shape, bool use_parallel_implementation)
56{
57 this->apply_blend_shapes(shape, 0, false, use_parallel_implementation);
58 shaped_positions = this->positions;
59 compute_joint_locations(shaped_positions);
60}
61
62template <typename T>
63void adaptive_skinned_mesh<T>::pose_mesh(const vec3_type& translation, const std::vector<vec3_type>& pose, bool apply_pose_correction, bool apply_lbs, bool use_parallel_implementation)
64{
65 std::vector<mat3_type> rotation_matrices;
66 compute_rotation_matrices(pose, rotation_matrices);
67 // on pose change apply pose correction to mesh positions
68 this->positions = shaped_positions;
69 if (apply_pose_correction)
70 this->apply_blend_shapes(compute_pose_correction_vector(rotation_matrices), nr_shapes, true, use_parallel_implementation);
71 if (apply_lbs)
72 this->lbs(this->compute_joint_transformations(this->joint_locations, translation, rotation_matrices), lbs_source_mode::position);
73 this->compute_vertex_normals(use_parallel_implementation);
74}
75
76
77template class adaptive_skinned_mesh<float>;
78
79 }
80 }
81}
matrix of fixed size dimensions
Definition fmat.h:23
Extension of dynamic_mesh that supports regression of joint locations from shaped mesh as well as pos...
void compute_alternative_joint_regressors()
compute the alternative joint regressors after shape blend shapes have been defined
void compute_rotation_matrices(const std::vector< vec3_type > &pose, std::vector< mat3_type > &rotation_matrices)
convertex vector of spin vectors resembling the pose into a vector of rotation matrices
std::vector< T > compute_pose_correction_vector(const std::vector< mat3_type > &rotation_matrices) const
given vector of rotation matrices, compute vector of pose correction weights by skipping matrix of ba...
void shape_mesh(const std::vector< T > &shape, bool use_parallel_implementation=false)
given shape weights, compute the rest pose shaped mesh vertex locations into the dynamic_mesh<T> memb...
void compute_joint_locations(const std::vector< vec3_type > &P)
given the vertex locations after applying the shape blend shapes, compute the member variable joint_l...
void pose_mesh(const vec3_type &translation, const std::vector< vec3_type > &pose, bool apply_pose_correction=true, bool apply_lbs=true, bool use_parallel_implementation=false)
starting with vertex position in member shaped_positions, optionally apply pose correction,...
the cgv namespace
Definition print.h:11