60 template<
typename MeshT>
67 weightsComputed_(false)
74 template<
typename MeshT>
82 template<
typename MeshT>
98 template<
typename MeshT>
106 if( !mesh_->get_property_handle(propDefaultPose, DEFAULTPOSE_PROP) )
107 mesh_->add_property(propDefaultPose, DEFAULTPOSE_PROP);
109 if (! mesh_->get_property_handle(propWeights, SKIN_WEIGHTS_PROP))
110 mesh_->add_property(propWeights, SKIN_WEIGHTS_PROP);
113 for(
typename MeshT::VertexIter it = mesh_->vertices_begin(); it != mesh_->vertices_end(); ++it)
114 mesh_->property(propDefaultPose, *it) =
DefaultPose(mesh_->point(*it), mesh_->normal(*it));
119 template<
typename MeshT>
122 deformSkin(lastAnimationHandle_, lastmethod_);
157 template<
typename MeshT>
162 if(!weightsComputed_) {
166 lastAnimationHandle_ = _hAni;
167 lastmethod_ = _method;
173 if(!mesh_->get_property_handle(propDefaultPose, DEFAULTPOSE_PROP) ||
174 !mesh_->get_property_handle(propWeights, SKIN_WEIGHTS_PROP))
177 Pose* pose = skeleton_->
pose(_hAni);
180 int verticesWithoutWeights = 0;
184 typename MeshT::VertexIter it;
186 std::vector< OpenMesh::VertexHandle > vhandles; vhandles.clear(); vhandles.reserve(mesh_->n_vertices());
187 for(it = mesh_->vertices_begin(); it != mesh_->vertices_end(); ++it){vhandles.push_back(*it);}
188 int vhcount = (int) vhandles.size();
189 #pragma omp parallel for 190 for (
int vhindex = 0; vhindex < vhcount; vhindex++)
192 for(it = mesh_->vertices_begin(); it != mesh_->vertices_end(); ++it)
202 OpenMesh::Vec3d default_point = mesh_->property(propDefaultPose, currentVertexH).point,
203 default_normal = mesh_->property(propDefaultPose, currentVertexH).normal;
207 if( _method == Blending::M_LBS ) {
210 SkinWeights &weights = mesh_->property(propWeights, currentVertexH);
213 if (weights.size() == 0)
215 verticesWithoutWeights++;
219 SkinWeights::iterator it_w;
220 for(it_w = weights.begin(); it_w != weights.end(); ++it_w)
228 }
else if( _method == Blending::M_DBS ) {
231 std::vector<double> weightVector;
232 std::vector<DualQuaternion> dualQuaternions;
234 SkinWeights &weights = mesh_->property(propWeights, currentVertexH);
235 SkinWeights::iterator it_w;
237 for(it_w = weights.begin(); it_w != weights.end(); ++it_w){
238 weightVector.push_back( it_w->second );
248 std::cerr <<
"ERROR: Unknown skinning method!" << std::endl;
251 mesh_->set_point(currentVertexH, point);
252 mesh_->set_normal(currentVertexH, normal);
256 if ( verticesWithoutWeights > 0 )
257 std::cerr <<
"Deform skin: " << verticesWithoutWeights <<
" vertices without skin weights." << std::endl;
260 mesh_->update_face_normals();
268 template<
typename MeshT>
275 if(mesh_->get_property_handle(propDefaultPose, DEFAULTPOSE_PROP))
277 typename MeshT::VertexIter it;
278 for(it = mesh_->vertices_begin(); it != mesh_->vertices_end(); ++it)
280 mesh_->set_point(*it, mesh_->property(propDefaultPose, *it).point);
281 mesh_->set_normal(*it, mesh_->property(propDefaultPose, *it).normal);
283 mesh_->remove_property(propDefaultPose);
288 mesh_->remove_property(propSkinWeights);
Abstract base class for the skin template, wrapping all template versions of the skin.
Handle for a vertex entity.
const DualQuaternion & unifiedDualQuaternion(size_t _joint)
Returns a dual quaternion holding the unified matrix represented as dual quaternion.
void releaseSkin()
The given mesh will be reset to its default pose and all skin properties are removed.
Holds the skins default pose.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
A general pose, used to store the frames of the animation.
Vec3 transform_vector(const Vec3 &_point) const
Transform a vector with the dual quaternion.
void attachSkin()
Attach the given mesh as skin to this skeleton.
A handle used to refer to an animation or to a specific frame in an animation.
General skin class, used to bind skeleton and mesh and deform the mesh.
static DualQuaternion interpolate(VectorType &_weights, const std::vector< DualQuaternion > &_dualQuaternions)
linear interpolation of dual quaternions. Result is normalized afterwards
SkinT(SkeletonT< PointT > *_skeleton, MeshT *_mesh, int _objectID)
constructor
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
DualQuaternion class for representing rigid motions in 3d.
const Matrix & unifiedMatrix(size_t _joint)
Returns the unified matrix.
Vec3 transform_point(const Vec3 &_point) const
Transform a point with the dual quaternion.
void deformSkin()
Attach the given mesh as skin to this skeleton.
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)