- Timestamp:
- 01/27/10 13:24:55 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osganimationskinning/osganimationskinning.cpp
r10697 r11009 19 19 #include <osgViewer/Viewer> 20 20 #include <osgGA/TrackballManipulator> 21 #include <osgDB/WriteFile> 21 22 #include <osgUtil/SmoothingVisitor> 22 23 #include <osg/io_utils> … … 26 27 #include <osgAnimation/RigGeometry> 27 28 #include <osgAnimation/BasicAnimationManager> 29 #include <osgAnimation/UpdateMatrixTransform> 30 #include <osgAnimation/UpdateBone> 31 #include <osgAnimation/StackedTransform> 32 #include <osgAnimation/StackedTranslateElement> 33 #include <osgAnimation/StackedRotateAxisElement> 28 34 29 35 osg::Geode* createAxis() … … 59 65 osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size) 60 66 { 61 osgAnimation::RigGeometry* geometry = new osgAnimation::RigGeometry; 62 67 osgAnimation::RigGeometry* riggeometry = new osgAnimation::RigGeometry; 68 69 osg::Geometry* geometry = new osg::Geometry; 63 70 osg::ref_ptr<osg::Vec3Array> vertices (new osg::Vec3Array()); 64 71 osg::ref_ptr<osg::Vec3Array> colors (new osg::Vec3Array()); … … 120 127 geometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, array->size(), &array->front())); 121 128 geometry->setUseDisplayList( false ); 122 return geometry; 129 riggeometry->setSourceGeometry(geometry); 130 return riggeometry; 123 131 } 124 132 … … 164 172 skelroot->setDefaultUpdateCallback(); 165 173 osg::ref_ptr<osgAnimation::Bone> root = new osgAnimation::Bone; 166 { 167 root->setBindMatrixInBoneSpace(osg::Matrix::identity()); 168 root->setBindMatrixInBoneSpace(osg::Matrix::translate(-1,0,0)); 169 root->setName("root"); 170 root->setDefaultUpdateCallback(); 171 } 174 root->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(-1,0,0))); 175 root->setName("root"); 176 osgAnimation::UpdateBone* pRootUpdate = new osgAnimation::UpdateBone("root"); 177 pRootUpdate->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate",osg::Vec3(-1,0,0))); 178 root->setUpdateCallback(pRootUpdate); 172 179 173 180 osg::ref_ptr<osgAnimation::Bone> right0 = new osgAnimation::Bone; 174 right0->set BindMatrixInBoneSpace(osg::Matrix::translate(1,0,0));181 right0->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(0,0,0))); 175 182 right0->setName("right0"); 176 right0->setDefaultUpdateCallback("right0"); 183 osgAnimation::UpdateBone* pRight0Update = new osgAnimation::UpdateBone("right0"); 184 pRight0Update->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate", osg::Vec3(1,0,0))); 185 pRight0Update->getStackedTransforms().push_back(new osgAnimation::StackedRotateAxisElement("rotate", osg::Vec3(0,0,1), 0)); 186 right0->setUpdateCallback(pRight0Update); 177 187 178 188 osg::ref_ptr<osgAnimation::Bone> right1 = new osgAnimation::Bone; 179 right1->set BindMatrixInBoneSpace(osg::Matrix::translate(1,0,0));189 right1->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(1,0,0))); 180 190 right1->setName("right1"); 181 right1->setDefaultUpdateCallback("right1"); 191 osgAnimation::UpdateBone* pRight1Update = new osgAnimation::UpdateBone("right1"); 192 pRight1Update->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate", osg::Vec3(1,0,0))); 193 pRight1Update->getStackedTransforms().push_back(new osgAnimation::StackedRotateAxisElement("rotate", osg::Vec3(0,0,1), 0)); 194 right1->setUpdateCallback(pRight1Update); 182 195 183 196 root->addChild(right0.get()); … … 191 204 osgAnimation::Animation* anim = new osgAnimation::Animation; 192 205 { 193 osgAnimation::QuatKeyframeContainer* keys0 = new osgAnimation::QuatKeyframeContainer; 194 osg::Quat rotate; 195 rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1)); 196 keys0->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1))); 197 keys0->push_back(osgAnimation::QuatKeyframe(3,rotate)); 198 keys0->push_back(osgAnimation::QuatKeyframe(6,rotate)); 199 osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler; 206 osgAnimation::FloatKeyframeContainer* keys0 = new osgAnimation::FloatKeyframeContainer; 207 keys0->push_back(osgAnimation::FloatKeyframe(0,0)); 208 keys0->push_back(osgAnimation::FloatKeyframe(3,osg::PI_2)); 209 keys0->push_back(osgAnimation::FloatKeyframe(6,osg::PI_2)); 210 osgAnimation::FloatLinearSampler* sampler = new osgAnimation::FloatLinearSampler; 200 211 sampler->setKeyframeContainer(keys0); 201 // osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(right0->getUpdateCallback()); 202 osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler); 203 channel->setName("quaternion"); 212 osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel(sampler); 213 channel->setName("rotate"); 204 214 channel->setTargetName("right0"); 205 215 anim->addChannel(channel); … … 207 217 208 218 { 209 osgAnimation::QuatKeyframeContainer* keys1 = new osgAnimation::QuatKeyframeContainer; 210 osg::Quat rotate; 211 rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1)); 212 keys1->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1))); 213 keys1->push_back(osgAnimation::QuatKeyframe(3,osg::Quat(0,0,0,1))); 214 keys1->push_back(osgAnimation::QuatKeyframe(6,rotate)); 215 osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler; 219 osgAnimation::FloatKeyframeContainer* keys1 = new osgAnimation::FloatKeyframeContainer; 220 keys1->push_back(osgAnimation::FloatKeyframe(0,0)); 221 keys1->push_back(osgAnimation::FloatKeyframe(3,0)); 222 keys1->push_back(osgAnimation::FloatKeyframe(6,osg::PI_2)); 223 osgAnimation::FloatLinearSampler* sampler = new osgAnimation::FloatLinearSampler; 216 224 sampler->setKeyframeContainer(keys1); 217 osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler); 218 //osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(right1->getUpdateCallback()); 219 channel->setName("quaternion"); 225 osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel(sampler); 226 channel->setName("rotate"); 220 227 channel->setTargetName("right1"); 221 228 anim->addChannel(channel); … … 246 253 geode->addDrawable(geom); 247 254 skelroot->addChild(geode); 248 osg::ref_ptr<osg::Vec3Array> src = dynamic_cast<osg::Vec3Array*>(geom->get VertexArray());255 osg::ref_ptr<osg::Vec3Array> src = dynamic_cast<osg::Vec3Array*>(geom->getSourceGeometry()->getVertexArray()); 249 256 geom->getOrCreateStateSet()->setMode(GL_LIGHTING, false); 250 257 geom->setDataVariance(osg::Object::DYNAMIC); … … 261 268 } 262 269 270 osgDB::writeNodeFile(*scene, "skinning.osg"); 263 271 return 0; 264 272 }
