cgv
Loading...
Searching...
No Matches
dynamic_mesh.h
1#pragma once
2
3#include <cgv/media/mesh/simple_mesh.h>
4
5#include "../lib_begin.h"
6
7namespace cgv {
8 namespace media {
9 namespace mesh {
10
13template <typename T = float>
14class CGV_API dynamic_mesh : public simple_mesh<T>
15{
16public:
17 using typename simple_mesh_base::idx_type;
18 using typename simple_mesh_base::idx2_type;
19 using typename simple_mesh_base::idx3_type;
20 using typename simple_mesh_base::idx4_type;
21 using typename simple_mesh_base::mat_type;
22 using typename simple_mesh<T>::vec2_type;
23 using typename simple_mesh<T>::vec3_type;
26 using typename simple_mesh<T>::mesh_type;
27 using typename simple_mesh<T>::mat3_type;
30
32 enum class blend_shape_mode {
34 direct,
36 indexed,
38 range_indexed
39 };
40
41 protected:
43 std::vector<vec3_type> reference_positions;
45 std::vector<vec3_type> intermediate_positions;
47 std::vector<vec3_type> blend_shape_data;
49 std::vector<uint32_t> blend_shape_indices;
61 std::vector<blend_shape> blend_shapes;
62
63public:
65 enum class vertex_weight_mode {
67 dense,
71 sparse,
77 fixed
78 };
79
80protected:
84 int32_t max_nr_weights_per_vertex = -1;
86 std::vector<int32_t> joint_parents;
88 std::vector<T> vertex_weight_data;
90 std::vector<uint32_t> vertex_weight_indices;
92 std::vector<uint32_t> vertex_weight_index_begins;
93public:
97 void store_in_reference_positions();
99 void store_in_intermediate_positions();
101 const std::vector<vec3_type>& get_intermediate_positions() const;
103 void recover_intermediate_positions();
105
113 uint32_t add_blend_shape(blend_shape_mode mode, idx_type nr_data, idx_type nr_indices = 0);
115 void add_blend_shape_data(const vec3_type& d);
117 void add_blend_shape_index(idx_type i);
121 bool has_blend_shape_vector(idx_type bi, idx_type vi) const;
125 vec3_type get_blend_shape_vector(idx_type bi, idx_type vi) const;
127 size_t get_nr_blend_shapes() const;
129
136 void apply_blend_shapes(const std::vector<T>& weights, idx_type blend_shape_offset = 0, bool only_add = false, bool use_parallel_implementation = false);
138
142 void set_vertex_weight_mode(vertex_weight_mode mode);
144 void begin_vertex_weight_vertex();
146 idx_type vertex_weight_begin(idx_type vi) const;
148 idx_type vertex_weight_end(idx_type vi) const;
150 T get_vertex_weight(idx_type vi, idx_type ji) const;
152 void add_vertex_weight_data(T w);
154 void add_vertex_weight_index(idx_type i);
156 size_t get_nr_vertex_weights() const;
158 size_t get_nr_vertex_weight_indices() const;
160 idx_type get_nr_joints() const;
162 std::vector<mat4_type> compute_joint_transformations(const std::vector<vec3_type>& reference_joint_locations,
163 const vec3_type& translation, const std::vector<vec3_type>& target_spin_vectors) const;
165 std::vector<mat4_type> compute_joint_transformations(const std::vector<vec3_type>& reference_joint_locations,
166 const vec3_type& translation, const std::vector<mat3_type>& target_rotations) const;
168 const std::vector<int32_t>& get_joint_parents() const;
170 std::vector<int32_t>& ref_joint_parents();
172 enum class lbs_source_mode {
174 reference,
176 position,
178 intermediate };
180
181 void lbs(const std::vector<mat4_type>& joint_matrices, lbs_source_mode mode);
183};
184 }
185 }
186}
187
188#include <cgv/config/lib_end.h>
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
matrix of fixed size dimensions
Definition fmat.h:23
A vector with zero based index.
Definition fvec.h:26
simple class to hold the material properties of a phong material
The dynamic_mesh provides interpolation between several blend shapes of a mesh.
std::vector< blend_shape > blend_shapes
Storage for all the blendshape definitions.
cgv::math::fvec< T, 4 > vec4_type
type of 4d vector
std::vector< int32_t > joint_parents
for each joint the index of the parent joint or -1 for root joints
std::vector< vec3_type > intermediate_positions
Storage for vertex positions after Linear Blend Skinning.
vertex_weight_mode
specifies how vertex weights are stored
std::vector< uint32_t > blend_shape_indices
Storage for the indices (if the blend shapes are defined by indices)
std::vector< vec3_type > reference_positions
Storage for vertex positions in the bind-pose.
std::vector< uint32_t > vertex_weight_index_begins
for each vertex the first index in vertex_weight_data and vertex_weight_indices
cgv::math::fmat< T, 4, 4 > mat4_type
linear transformation
vertex_weight_mode weight_mode
How the vertex weights are stored for this instance.
blend_shape_mode
specifies how the blend shapes are stored
std::vector< uint32_t > vertex_weight_indices
continuous storage of vertex indices
std::vector< vec3_type > blend_shape_data
Storage for the blend shape vertices.
std::vector< T > vertex_weight_data
continuous storage of all vertex weights
lbs_source_mode
Which source to use for the Linear Blend Skinning.
cgv::type::uint32_type idx_type
define index type
Definition simple_mesh.h:30
the simple_mesh class is templated over the coordinate type that defaults to float
the cgv namespace
Definition print.h:11
Captures where and how the blandshape data is stored.
blend_shape_mode mode
How the blendshape is stored.
idx2_type blend_shape_index_range
The range of indices (indices into a std::vector!) which hold the indices into the data-buffer.
idx2_type blend_shape_data_range
The range of indices (indices into a std::vector!) which hold the blendshape vertices.