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 == 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 == 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);
DualQuaternion class for representing rigid motions in 3d.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Method
Possible deformation methods.
Vec3 transform_vector(const Vec3 &_point) const
Transform a vector with the dual quaternion.
A general pose, used to store the frames of the animation.
A handle used to refer to an animation or to a specific frame in an animation.
static DualQuaternion interpolate(VectorType &_weights, const std::vector< DualQuaternion > &_dualQuaternions)
linear interpolation of dual quaternions. Result is normalized afterwards
void attachSkin()
Attach the given mesh as skin to this skeleton.
Abstract base class for the skin template, wrapping all template versions of the skin.
Handle for a vertex entity.
Vec3 transform_point(const Vec3 &_point) const
Transform a point with the dual quaternion.
const DualQuaternion & unifiedDualQuaternion(unsigned int _joint)
Returns a dual quaternion holding the unified matrix represented as dual quaternion.
SkinT(SkeletonT< PointT > *_skeleton, MeshT *_mesh, int _objectID)
constructor
Holds the skins default pose.
void releaseSkin()
The given mesh will be reset to its default pose and all skin properties are removed.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
const Matrix & unifiedMatrix(unsigned int _joint)
Returns the unified matrix.
General skin class, used to bind skeleton and mesh and deform the mesh.
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
void deformSkin()
Attach the given mesh as skin to this skeleton.