From da79cd85e4895fe7fbd5ed1619cae4c2f9434867 Mon Sep 17 00:00:00 2001 From: Paul MARTZ Date: Sat, 13 Mar 2010 23:08:16 +0000 Subject: [PATCH] Merge 11009 to 2.8 branch (just examples directory). --- .../osganimationhardware.cpp | 17 ++++- .../osganimationskinning.cpp | 74 ++++++++++--------- .../osganimationsolid/osganimationsolid.cpp | 9 ++- 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/examples/osganimationhardware/osganimationhardware.cpp b/examples/osganimationhardware/osganimationhardware.cpp index 420387f64..ed3d9163e 100644 --- a/examples/osganimationhardware/osganimationhardware.cpp +++ b/examples/osganimationhardware/osganimationhardware.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -43,6 +44,15 @@ osg::ref_ptr program; // show how to override the default RigTransformHardware for customized usage struct MyRigTransformHardware : public osgAnimation::RigTransformHardware { + + void operator()(osgAnimation::RigGeometry& geom) + { + if (_needInit) + if (!init(geom)) + return; + computeMatrixPaletteUniform(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry()); + } + bool init(osgAnimation::RigGeometry& geom) { osg::Vec3Array* pos = dynamic_cast(geom.getVertexArray()); @@ -56,7 +66,9 @@ struct MyRigTransformHardware : public osgAnimation::RigTransformHardware return false; } - osgAnimation::Bone::BoneMap bm = geom.getSkeleton()->getBoneMap(); + osgAnimation::BoneMapVisitor mapVisitor; + geom.getSkeleton()->accept(mapVisitor); + osgAnimation::BoneMap bm = mapVisitor.getBoneMap(); if (!createPalette(pos->size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList())) return false; @@ -136,8 +148,11 @@ struct SetupRigGeometry : public osg::NodeVisitor rig->setRigTransformImplementation(new MyRigTransformHardware); } +#if 0 if (geom.getName() != std::string("BoundingBox")) // we disable compute of bounding box for all geometry except our bounding box geom.setComputeBoundingBoxCallback(new osg::Drawable::ComputeBoundingBoxCallback); +// geom.setInitialBound(new osg::Drawable::ComputeBoundingBoxCallback); +#endif } }; diff --git a/examples/osganimationskinning/osganimationskinning.cpp b/examples/osganimationskinning/osganimationskinning.cpp index 66e81a3fd..2cfba6cbc 100644 --- a/examples/osganimationskinning/osganimationskinning.cpp +++ b/examples/osganimationskinning/osganimationskinning.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,11 @@ #include #include #include +#include +#include +#include +#include +#include osg::Geode* createAxis() { @@ -58,8 +64,9 @@ osg::Geode* createAxis() osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size) { - osgAnimation::RigGeometry* geometry = new osgAnimation::RigGeometry; + osgAnimation::RigGeometry* riggeometry = new osgAnimation::RigGeometry; + osg::Geometry* geometry = new osg::Geometry; osg::ref_ptr vertices (new osg::Vec3Array()); osg::ref_ptr colors (new osg::Vec3Array()); geometry->setVertexArray (vertices.get()); @@ -119,7 +126,8 @@ osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size) geometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, array->size(), &array->front())); geometry->setUseDisplayList( false ); - return geometry; + riggeometry->setSourceGeometry(geometry); + return riggeometry; } @@ -163,22 +171,27 @@ int main (int argc, char* argv[]) osg::ref_ptr skelroot = new osgAnimation::Skeleton; skelroot->setDefaultUpdateCallback(); osg::ref_ptr root = new osgAnimation::Bone; - { - root->setBindMatrixInBoneSpace(osg::Matrix::identity()); - root->setBindMatrixInBoneSpace(osg::Matrix::translate(-1,0,0)); - root->setName("root"); - root->setDefaultUpdateCallback(); - } + root->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(-1,0,0))); + root->setName("root"); + osgAnimation::UpdateBone* pRootUpdate = new osgAnimation::UpdateBone("root"); + pRootUpdate->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate",osg::Vec3(-1,0,0))); + root->setUpdateCallback(pRootUpdate); osg::ref_ptr right0 = new osgAnimation::Bone; - right0->setBindMatrixInBoneSpace(osg::Matrix::translate(1,0,0)); + right0->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(0,0,0))); right0->setName("right0"); - right0->setDefaultUpdateCallback("right0"); + osgAnimation::UpdateBone* pRight0Update = new osgAnimation::UpdateBone("right0"); + pRight0Update->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate", osg::Vec3(1,0,0))); + pRight0Update->getStackedTransforms().push_back(new osgAnimation::StackedRotateAxisElement("rotate", osg::Vec3(0,0,1), 0)); + right0->setUpdateCallback(pRight0Update); osg::ref_ptr right1 = new osgAnimation::Bone; - right1->setBindMatrixInBoneSpace(osg::Matrix::translate(1,0,0)); + right1->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(1,0,0))); right1->setName("right1"); - right1->setDefaultUpdateCallback("right1"); + osgAnimation::UpdateBone* pRight1Update = new osgAnimation::UpdateBone("right1"); + pRight1Update->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate", osg::Vec3(1,0,0))); + pRight1Update->getStackedTransforms().push_back(new osgAnimation::StackedRotateAxisElement("rotate", osg::Vec3(0,0,1), 0)); + right1->setUpdateCallback(pRight1Update); root->addChild(right0.get()); right0->addChild(right1.get()); @@ -190,33 +203,27 @@ int main (int argc, char* argv[]) osgAnimation::Animation* anim = new osgAnimation::Animation; { - osgAnimation::QuatKeyframeContainer* keys0 = new osgAnimation::QuatKeyframeContainer; - osg::Quat rotate; - rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1)); - keys0->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1))); - keys0->push_back(osgAnimation::QuatKeyframe(3,rotate)); - keys0->push_back(osgAnimation::QuatKeyframe(6,rotate)); - osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler; + osgAnimation::FloatKeyframeContainer* keys0 = new osgAnimation::FloatKeyframeContainer; + keys0->push_back(osgAnimation::FloatKeyframe(0,0)); + keys0->push_back(osgAnimation::FloatKeyframe(3,osg::PI_2)); + keys0->push_back(osgAnimation::FloatKeyframe(6,osg::PI_2)); + osgAnimation::FloatLinearSampler* sampler = new osgAnimation::FloatLinearSampler; sampler->setKeyframeContainer(keys0); - // osgAnimation::AnimationUpdateCallback* cb = dynamic_cast(right0->getUpdateCallback()); - osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler); - channel->setName("quaternion"); + osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel(sampler); + channel->setName("rotate"); channel->setTargetName("right0"); anim->addChannel(channel); } { - osgAnimation::QuatKeyframeContainer* keys1 = new osgAnimation::QuatKeyframeContainer; - osg::Quat rotate; - rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1)); - keys1->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1))); - keys1->push_back(osgAnimation::QuatKeyframe(3,osg::Quat(0,0,0,1))); - keys1->push_back(osgAnimation::QuatKeyframe(6,rotate)); - osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler; + osgAnimation::FloatKeyframeContainer* keys1 = new osgAnimation::FloatKeyframeContainer; + keys1->push_back(osgAnimation::FloatKeyframe(0,0)); + keys1->push_back(osgAnimation::FloatKeyframe(3,0)); + keys1->push_back(osgAnimation::FloatKeyframe(6,osg::PI_2)); + osgAnimation::FloatLinearSampler* sampler = new osgAnimation::FloatLinearSampler; sampler->setKeyframeContainer(keys1); - osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler); - //osgAnimation::AnimationUpdateCallback* cb = dynamic_cast(right1->getUpdateCallback()); - channel->setName("quaternion"); + osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel(sampler); + channel->setName("rotate"); channel->setTargetName("right1"); anim->addChannel(channel); } @@ -245,7 +252,7 @@ int main (int argc, char* argv[]) osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); skelroot->addChild(geode); - osg::ref_ptr src = dynamic_cast(geom->getVertexArray()); + osg::ref_ptr src = dynamic_cast(geom->getSourceGeometry()->getVertexArray()); geom->getOrCreateStateSet()->setMode(GL_LIGHTING, false); geom->setDataVariance(osg::Object::DYNAMIC); @@ -260,6 +267,7 @@ int main (int argc, char* argv[]) viewer.frame(); } + osgDB::writeNodeFile(*scene, "skinning.osg"); return 0; } diff --git a/examples/osganimationsolid/osganimationsolid.cpp b/examples/osganimationsolid/osganimationsolid.cpp index 6fd67c7a2..6ce649b78 100644 --- a/examples/osganimationsolid/osganimationsolid.cpp +++ b/examples/osganimationsolid/osganimationsolid.cpp @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -22,7 +22,8 @@ #include #include -#include +#include +#include using namespace osgAnimation; @@ -74,7 +75,9 @@ int main (int argc, char* argv[]) osg::ref_ptr trans = new osg::MatrixTransform(); trans->setName("AnimatedNode"); trans->setDataVariance(osg::Object::DYNAMIC); - trans->setUpdateCallback(new osgAnimation::UpdateTransform("AnimatedCallback")); + osgAnimation::UpdateMatrixTransform* updatecb = new osgAnimation::UpdateMatrixTransform("AnimatedCallback"); + updatecb->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("position")); + trans->setUpdateCallback(updatecb); trans->setMatrix(osg::Matrix::identity()); trans->addChild (geode.get());