Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_SKINNING_LBS_SKINNING_LBS_H
00002 #define OPENTISSUE_KINEMATICS_SKINNING_LBS_SKINNING_LBS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/trimesh/trimesh.h>
00013 #include <OpenTissue/core/containers/mesh/trimesh/util/trimesh_util.h>
00014 #include <OpenTissue/kinematics/skinning/skinning_traits.h>
00015 #include <OpenTissue/utility/gl/gl_draw_mesh.h>
00016 #include <cassert>
00017 #include <vector>
00018
00019
00020 namespace OpenTissue
00021 {
00022 namespace skinning
00023 {
00024
00025 template<typename types>
00026 class LBS : public trimesh::TriMesh<types,SkinVertexTraits<types> ,SkinFaceTraits<types>, trimesh::TriMeshArrayKernel >
00027 {
00028 public:
00029
00030
00031 typedef int no_gpu_support;
00032
00033 typedef typename types::matrix3x3_type matrix3x3_type;
00034 typedef typename types::quaternion_type quaternion_type;
00035 typedef typename types::vector3_type vector3_type;
00036 typedef typename types::real_type real_type;
00037
00038
00039 typedef trimesh::TriMesh< types, SkinVertexTraits<types>, SkinFaceTraits<types>, OpenTissue::trimesh::TriMeshArrayKernel > base_mesh;
00040
00041 public:
00042
00043 int m_material_idx;
00044
00045 public:
00046
00047 LBS()
00048 : m_material_idx(-1)
00049 {}
00050
00051 public:
00052
00053 bool empty() const
00054 {
00055 return (!(base_mesh::size_faces()>0));
00056 }
00057
00058 template<typename skin_container_type>
00059 static void init_skin_render( skin_container_type & scont )
00060 {
00061 }
00062
00063 template<typename skin_container_type>
00064 static void cleanup_skin_render( skin_container_type & scont )
00065 {
00066 }
00067
00068 template<typename skin_container_type>
00069 static void pre_render( skin_container_type & scont )
00070 {
00071 }
00072
00073 template<typename skin_container_type>
00074 static void post_render( skin_container_type & scont )
00075 {
00076 }
00077
00086 template<typename skeleton_type, typename skin_container_type>
00087 void update( skeleton_type & skeleton, skin_container_type & scont )
00088 {
00089 typedef typename skeleton_type::bone_traits bone_traits;
00090 typedef typename types::coordsys_type coordsys_type;
00091
00092
00093 if(this->empty())
00094 return;
00095
00096 typedef typename skeleton_type::bone_type bone_type;
00097
00098 typename base_mesh::vertex_iterator vertex = base_mesh::vertex_begin();
00099 typename base_mesh::vertex_iterator end = base_mesh::vertex_end();
00100
00101 for(;vertex!=end;++vertex)
00102 {
00103 vertex->m_coord = vector3_type(0,0,0);
00104 vertex->m_normal = vector3_type(0,0,0);
00105
00106 for(int i= 0; i < vertex->m_influences; ++i)
00107 {
00108 vector3_type p = vertex->m_original_coord;
00109 vector3_type n = vertex->m_original_normal;
00110 bone_type const * bone = skeleton.get_bone(vertex->m_bone[i]);
00111
00112 coordsys_type bone_space_transform = bone_traits::convert( bone->bone_space_transform() );
00113
00114 bone_space_transform.xform_point(p);
00115 bone_space_transform.xform_vector(n);
00116 vertex->m_coord += vertex->m_weight[i] * p;
00117 vertex->m_normal += vertex->m_weight[i] * n;
00118 }
00119 }
00120 }
00121
00122 };
00123
00124 }
00125 }
00126
00127
00128 #endif