osgAnimation.RigGeometry是一个带骨骼的几何模型,它被用于实现动画的解析与应用。它包含一个几何模型和一组骨骼,每个骨骼与几何模型的一个顶点相关联。
osg::Referenced -> osg::Object -> osg::Drawable -> osg::Geometry -> osgAnimation::RigGeometry
osg::ref_ptr<osgAnimation::RigGeometry> rigGeom = new osgAnimation::RigGeometry();
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
// 设置几何模型的顶点数据
...
rigGeom->setGeometry(geom);
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone();
// 设置骨骼的名称
bone->setName("bone1");
// 设置骨骼的初始姿态
...
// 将骨骼添加到RigGeometry中
rigGeom->addBone(bone);
unsigned int vertexIndex = 0; // 顶点的索引,假设为0
int boneIndex = 0; // 骨骼的索引,假设为0
osg::Geometry* geom = rigGeom->getGeometry();
if (geom && geom->getVertexArray() && geom->getVertexArray()->getNumElements() > vertexIndex)
{
osgVector3Array* vertices = dynamic_cast<osgVector3Array*>(geom->getVertexArray());
if (vertices)
{
osg::Vec3& vertex = (*vertices)[vertexIndex];
// 关联顶点和骨骼
rigGeom->addVertexBoneAssignment(vertexIndex, boneIndex, 1.0f);
}
}
// 创建一个AnimationManagerBase实例
osg::ref_ptr<osgAnimation::AnimationManagerBase> animManager = new osgAnimation::BasicAnimationManager();
// 为RigGeometry设置AnimationManagerBase
rigGeom->setUpdateCallback(new osgAnimation::UpdateBoneVisitor(animManager.get()));