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;
60
61 std::vector<blend_shape> blend_shapes;
62
63public:
65 enum class vertex_weight_mode {
67 dense,
71 sparse,
77 fixed
78 };
79
80protected:
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:
96
101 const std::vector<vec3_type>& get_intermediate_positions() const;
105
108
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);
121 bool has_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
141
142 void set_vertex_weight_mode(vertex_weight_mode mode);
144 void begin_vertex_weight_vertex();
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>
matrix of fixed size dimensions
Definition fmat.h:23
A vector with zero based index.
Definition fvec.h:29
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
void add_blend_shape_data(const vec3_type &d)
Add another data point to the data buffer.
cgv::type::uint32_type idx_type
define index type
Definition simple_mesh.h:30
void recover_intermediate_positions()
copy intermediate positions to positions
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.
std::vector< int32_t > & ref_joint_parents()
return mutable reference to joint parent vector
vertex_weight_mode
specifies how vertex weights are stored
uint32_t add_blend_shape(blend_shape_mode mode, idx_type nr_data, idx_type nr_indices=0)
Add a new blend shape.
void store_in_intermediate_positions()
store current positions in intermediate positions
void store_in_reference_positions()
store current positions in reference positions
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.
void add_blend_shape_index(idx_type i)
Add another index to the index buffer.
std::vector< uint32_t > vertex_weight_index_begins
for each vertex the first index in vertex_weight_data and vertex_weight_indices
idx_type vertex_weight_begin(idx_type vi) const
return the begin index for vertex weights of given vertex
int32_t max_nr_weights_per_vertex
in case of fixed vertex_weight_mode the number of weights per vertex
cgv::math::fmat< T, 4, 4 > mat4_type
linear transformation
vec3_type get_blend_shape_vector(idx_type bi, idx_type vi) const
Returns one vertex of one blend shape.
const std::vector< int32_t > & get_joint_parents() const
return const reference to joint parent vector
bool has_blend_shape_vector(idx_type bi, idx_type vi) const
Query if a blend shape has a vertex with a given ID.
void apply_blend_shapes(const std::vector< T > &weights, idx_type blend_shape_offset=0, bool only_add=false, bool use_parallel_implementation=false)
this function applies weights.size() number of blend shapes starting at offset blend_shape_offset and...
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
idx_type vertex_weight_end(idx_type vi) const
return the end index for vertex weights of given vertex
T get_vertex_weight(idx_type vi, idx_type ji) const
return the vertex weight of vertex vi and joint ji
const std::vector< vec3_type > & get_intermediate_positions() const
return const reference to intermediate position vector
lbs_source_mode
Which source to use for the Linear Blend Skinning.
std::vector< mat4_type > compute_joint_transformations(const std::vector< vec3_type > &reference_joint_locations, const vec3_type &translation, const std::vector< vec3_type > &target_spin_vectors) const
compute joint transformations from reference joint locations, target translation and target spin vect...
cgv::math::fvec< idx_type, 2 > idx2_type
define index pair type
Definition simple_mesh.h:32
size_t get_nr_blend_shapes() const
Return how many blend shapes this mesh has.
cgv::type::uint32_type idx_type
define index type
Definition simple_mesh.h:30
cgv::math::fvec< idx_type, 4 > idx4_type
define index quadruple type
Definition simple_mesh.h:36
illum::textured_surface_material mat_type
define material type
Definition simple_mesh.h:38
cgv::math::fvec< idx_type, 2 > idx2_type
define index pair type
Definition simple_mesh.h:32
cgv::math::fvec< idx_type, 3 > idx3_type
define index triple type
Definition simple_mesh.h:34
cgv::math::fvec< T, 2 > vec2_type
type of 2d vector
cgv::math::fmat< T, 3, 3 > mat3_type
linear transformation
cgv::math::fvec< T, 3 > vec3_type
type of 3d vector
simple_mesh< T > mesh_type
type of axis aligned 3d box
simple_mesh(const simple_mesh< float > &sm)
this header is dependency free
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.