diff --git a/include/osgAnimation/Animation b/include/osgAnimation/Animation index 7f00b12a4..3748f8cae 100644 --- a/include/osgAnimation/Animation +++ b/include/osgAnimation/Animation @@ -47,6 +47,9 @@ namespace osgAnimation // addChannel insert the channel and call the computeDuration function void addChannel (Channel* pChannel); + // removeChannel remove the channel from channels list and call the computeDuration function + void removeChannel (Channel* pChannel); + /** Those accessors let you add and remove channels * if you modify something that can change the duration * you are supposed to call computeDuration or setDuration @@ -61,16 +64,13 @@ namespace osgAnimation */ void setDuration(double duration); - /** Compute duration from channel and keyframes * if the duration is not specified you should * call this method before using it */ void computeDuration(); - double getDuration() const; - void setWeight (float weight); float getWeight() const; @@ -85,10 +85,10 @@ namespace osgAnimation protected: - double computeDurationFromChannels() const; - ~Animation() {} + double computeDurationFromChannels() const; + double _duration; double _originalDuration; float _weight; diff --git a/include/osgAnimation/AnimationManagerBase b/include/osgAnimation/AnimationManagerBase index faf763d1e..bdc0c5c89 100644 --- a/include/osgAnimation/AnimationManagerBase +++ b/include/osgAnimation/AnimationManagerBase @@ -40,6 +40,7 @@ namespace osgAnimation virtual void update(double t) = 0; virtual bool needToLink() const; const AnimationList& getAnimationList() const { return _animations;} + AnimationList& getAnimationList() { return _animations;} /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); diff --git a/include/osgAnimation/Channel b/include/osgAnimation/Channel index 0b3df05f4..365c3a55c 100644 --- a/include/osgAnimation/Channel +++ b/include/osgAnimation/Channel @@ -25,10 +25,11 @@ #include #include + namespace osgAnimation { - class OSGANIMATION_EXPORT Channel : public osg::Referenced + class OSGANIMATION_EXPORT Channel : public osg::Object { public: @@ -37,6 +38,10 @@ namespace osgAnimation virtual ~Channel(); virtual Channel* clone() const = 0; + virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* libraryName() const { return "osgAnimation"; } + virtual const char* className() const { return "Channel"; } + virtual void update(double time, float weight, int priority) = 0; virtual void reset() = 0; virtual Target* getTarget() = 0; @@ -74,6 +79,9 @@ namespace osgAnimation typedef typename SamplerType::UsingType UsingType; typedef TemplateTarget TargetType; typedef TemplateKeyframeContainer KeyframeContainerType; + + Object* cloneType() const { return new TemplateChannel(); } + Object* clone(const osg::CopyOp& copyop) const { return new TemplateChannel(*this); } Channel* clone() const { return new TemplateChannel(*this); } TemplateChannel (const TemplateChannel& channel) : @@ -170,8 +178,10 @@ namespace osgAnimation typedef TemplateChannel FloatLinearChannel; typedef TemplateChannel Vec2LinearChannel; typedef TemplateChannel Vec3LinearChannel; + typedef TemplateChannel Vec3usLinearChannel; // quantized Vec3LinearChannel typedef TemplateChannel Vec4LinearChannel; typedef TemplateChannel QuatSphericalLinearChannel; + typedef TemplateChannel Vec3usSphericalLinearChannel; // quantized QuatSphericalLinearChannel typedef TemplateChannel MatrixLinearChannel; typedef TemplateChannel FloatCubicBezierChannel; diff --git a/include/osgAnimation/CubicBezier b/include/osgAnimation/CubicBezier index 7291c281c..54e443879 100644 --- a/include/osgAnimation/CubicBezier +++ b/include/osgAnimation/CubicBezier @@ -21,11 +21,11 @@ namespace osgAnimation { + template class TemplateCubicBezier { public: - TemplateCubicBezier() : _position(osg::default_value()), _controlPointIn(osg::default_value()), _controlPointOut(osg::default_value()) {} TemplateCubicBezier(const T& p, const T& i, const T& o) : _position(p), _controlPointIn(i), _controlPointOut(o) @@ -49,6 +49,9 @@ namespace osgAnimation void setControlPointIn(const T& v) {_controlPointIn = v;} void setControlPointOut(const T& v) {_controlPointOut = v;} + bool operator==(const TemplateCubicBezier& other) const + { return _position == other._position && _controlPointIn == other._controlPointIn && _controlPointOut == other._controlPointOut; } + // steaming operators. friend std::ostream& operator << (std::ostream& output, const TemplateCubicBezier& tcb) { diff --git a/include/osgAnimation/Interpolator b/include/osgAnimation/Interpolator index 28c9b789f..bf4f1cd29 100644 --- a/include/osgAnimation/Interpolator +++ b/include/osgAnimation/Interpolator @@ -221,9 +221,11 @@ namespace osgAnimation typedef TemplateLinearInterpolator FloatLinearInterpolator; typedef TemplateLinearInterpolator Vec2LinearInterpolator; typedef TemplateLinearInterpolator Vec3LinearInterpolator; + typedef TemplateLinearInterpolator Vec3usLinearInterpolator; typedef TemplateLinearInterpolator Vec3PackedLinearInterpolator; typedef TemplateLinearInterpolator Vec4LinearInterpolator; typedef TemplateSphericalLinearInterpolator QuatSphericalLinearInterpolator; + typedef TemplateSphericalLinearInterpolator Vec3usSphericalLinearInterpolator; typedef TemplateLinearInterpolator MatrixLinearInterpolator; typedef TemplateCubicBezierInterpolator FloatCubicBezierInterpolator; diff --git a/include/osgAnimation/Keyframe b/include/osgAnimation/Keyframe index f28a601f8..cfab59a58 100644 --- a/include/osgAnimation/Keyframe +++ b/include/osgAnimation/Keyframe @@ -17,12 +17,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include namespace osgAnimation @@ -45,6 +47,8 @@ namespace osgAnimation protected: T _value; public: + typedef T value_type; + TemplateKeyframe () {} ~TemplateKeyframe () {} @@ -71,19 +75,19 @@ namespace osgAnimation template - class TemplateKeyframeContainer : public std::vector >, public KeyframeContainer + class TemplateKeyframeContainer : public osg::MixinVector >, public KeyframeContainer { public: // const char* getKeyframeType() { return #T ;} TemplateKeyframeContainer() {} typedef TemplateKeyframe KeyType; - - virtual unsigned int size() const { return (unsigned int)std::vector >::size(); } + typedef typename osg::MixinVector< TemplateKeyframe > VectorType; + virtual unsigned int size() const { return (unsigned int)osg::MixinVector >::size(); } }; template <> - class TemplateKeyframeContainer : public std::vector >, public KeyframeContainer + class TemplateKeyframeContainer : public osg::MixinVector >, public KeyframeContainer { public: typedef TemplateKeyframe KeyType; @@ -109,12 +113,18 @@ namespace osgAnimation typedef TemplateKeyframe Vec3Keyframe; typedef TemplateKeyframeContainer Vec3KeyframeContainer; + typedef TemplateKeyframe Vec3usKeyframe; + typedef TemplateKeyframeContainer Vec3usKeyframeContainer; + typedef TemplateKeyframe Vec4Keyframe; typedef TemplateKeyframeContainer Vec4KeyframeContainer; typedef TemplateKeyframe QuatKeyframe; typedef TemplateKeyframeContainer QuatKeyframeContainer; + typedef TemplateKeyframe Vec3usKeyframe; + typedef TemplateKeyframeContainer Vec3usKeyframeContainer; + typedef TemplateKeyframe MatrixKeyframe; typedef TemplateKeyframeContainer MatrixKeyframeContainer; diff --git a/include/osgAnimation/RigGeometry b/include/osgAnimation/RigGeometry index f35404cbc..78c290d8e 100644 --- a/include/osgAnimation/RigGeometry +++ b/include/osgAnimation/RigGeometry @@ -52,7 +52,7 @@ namespace osgAnimation public: RigGeometry(); -// RigGeometry(const osg::Geometry& b); + RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); META_Object(osgAnimation, RigGeometry); @@ -123,7 +123,7 @@ namespace osgAnimation }; - struct UpdateRigGeometry : public osg::DrawableUpdateCallback + struct UpdateRigGeometry : public osg::Drawable::UpdateCallback { UpdateRigGeometry() {} @@ -131,7 +131,7 @@ namespace osgAnimation META_Object(osgAnimation, UpdateRigGeometry); - virtual void update(osg::NodeVisitor*, osg::Drawable* drw) { + virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw) { RigGeometry* geom = dynamic_cast(drw); if(!geom) return; @@ -157,6 +157,12 @@ namespace osgAnimation if(geom->getNeedToComputeMatrix()) geom->computeMatrixFromRootSkeleton(); + if(geom->getSourceGeometry()) { + osg::Drawable::UpdateCallback * up = dynamic_cast(geom->getSourceGeometry()->getUpdateCallback()); + if(up) + up->update(nv, geom->getSourceGeometry()); + } + geom->update(); } }; diff --git a/include/osgAnimation/RigTransformHardware b/include/osgAnimation/RigTransformHardware index 54ba61520..f8dd86da2 100644 --- a/include/osgAnimation/RigTransformHardware +++ b/include/osgAnimation/RigTransformHardware @@ -34,6 +34,7 @@ namespace osgAnimation typedef osgAnimation::Bone BoneType; typedef std::vector > BoneWeightAttribList; typedef std::vector > BonePalette; + typedef std::map BoneNamePaletteIndex; typedef std::vector MatrixPalette; struct IndexWeightEntry @@ -63,6 +64,10 @@ namespace osgAnimation virtual void operator()(RigGeometry&); void setShader(osg::Shader*); + const BoneNamePaletteIndex& getBoneNameToPalette() { + return _boneNameToPalette; + } + protected: bool init(RigGeometry&); @@ -74,6 +79,7 @@ namespace osgAnimation int _nbVertexes; VertexIndexWeightList _vertexIndexMatrixWeightList; BonePalette _bonePalette; + BoneNamePaletteIndex _boneNameToPalette; BoneWeightAttribList _boneWeightAttribArrays; osg::ref_ptr _uniformMatrixPalette; osg::ref_ptr _shader; diff --git a/include/osgAnimation/RigTransformSoftware b/include/osgAnimation/RigTransformSoftware index ab2f60c78..ae4debd85 100644 --- a/include/osgAnimation/RigTransformSoftware +++ b/include/osgAnimation/RigTransformSoftware @@ -166,6 +166,7 @@ namespace osgAnimation bool _needInit; + std::map _invalidInfluence; }; } diff --git a/include/osgAnimation/Sampler b/include/osgAnimation/Sampler index 26730c880..53be9407e 100644 --- a/include/osgAnimation/Sampler +++ b/include/osgAnimation/Sampler @@ -123,8 +123,10 @@ namespace osgAnimation typedef TemplateSampler FloatLinearSampler; typedef TemplateSampler Vec2LinearSampler; typedef TemplateSampler Vec3LinearSampler; + typedef TemplateSampler Vec3usLinearSampler; typedef TemplateSampler Vec4LinearSampler; typedef TemplateSampler QuatSphericalLinearSampler; + typedef TemplateSampler Vec3usSphericalLinearSampler; typedef TemplateSampler MatrixLinearSampler; typedef TemplateSampler FloatCubicBezierSampler; diff --git a/include/osgAnimation/StackedTransform b/include/osgAnimation/StackedTransform index 296dc5f74..c91a51996 100644 --- a/include/osgAnimation/StackedTransform +++ b/include/osgAnimation/StackedTransform @@ -32,9 +32,6 @@ namespace osgAnimation const osg::Matrix& getMatrix() const; protected: - - typedef osg::MixinVector > inherited; - osg::Matrix _matrix; }; diff --git a/include/osgDB/StreamOperator b/include/osgDB/StreamOperator index 3c352e219..c4abc1331 100644 --- a/include/osgDB/StreamOperator +++ b/include/osgDB/StreamOperator @@ -90,7 +90,7 @@ public: void setSupportBinaryBrackets( bool b ) { _supportBinaryBrackets = b; } bool getSupportBinaryBrackets() const { return _supportBinaryBrackets; } - void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; } + void checkStream() const; bool isFailed() const { return _failed; } virtual bool isBinary() const = 0; diff --git a/src/osgAnimation/Action.cpp b/src/osgAnimation/Action.cpp index 26e309d0e..4c89143a5 100644 --- a/src/osgAnimation/Action.cpp +++ b/src/osgAnimation/Action.cpp @@ -22,8 +22,16 @@ Action::Action() _fps = 25; _speed = 1.0; _loop = 1; + _state = Stop; +} +Action::Action(const Action&rhs,const osg::CopyOp&) +{ + _numberFrame = rhs._numberFrame; + _fps = rhs._fps; + _speed = rhs._speed; + _loop = rhs._loop; + _state = Stop; } -Action::Action(const Action&,const osg::CopyOp&) {} Action::Callback* Action::getFrameCallback(unsigned int frame) { if (_framesCallback.find(frame) != _framesCallback.end()) diff --git a/src/osgAnimation/ActionVisitor.cpp b/src/osgAnimation/ActionVisitor.cpp index 611acb39f..650c75772 100644 --- a/src/osgAnimation/ActionVisitor.cpp +++ b/src/osgAnimation/ActionVisitor.cpp @@ -140,8 +140,8 @@ void UpdateActionVisitor::apply(ActionAnimation& action) { unsigned int frame = getLocalFrame(); apply(static_cast(action)); - int pri = static_cast(_currentAnimationPriority); - _currentAnimationPriority++; + int pri = static_cast(_currentAnimationPriority); + _currentAnimationPriority++; action.updateAnimation(frame, -pri); } } @@ -159,6 +159,7 @@ void UpdateActionVisitor::apply(ActionStripAnimation& action) ClearActionVisitor::ClearActionVisitor(ClearType type) : _clearType(type) { + _frame = 0; } void ClearActionVisitor::apply(Timeline& tm) diff --git a/src/osgAnimation/Animation.cpp b/src/osgAnimation/Animation.cpp index 6df09c17f..3a0f665db 100644 --- a/src/osgAnimation/Animation.cpp +++ b/src/osgAnimation/Animation.cpp @@ -40,8 +40,27 @@ void Animation::addChannel(Channel* pChannel) _originalDuration = computeDurationFromChannels(); } + +void Animation::removeChannel(Channel* pChannel) +{ + ChannelList::iterator it = _channels.begin(); + while(it != _channels.end() && it->get() != pChannel) + { + ++ it; + } + + if (it != _channels.end()) + { + _channels.erase(it); + } + computeDuration(); +} + double Animation::computeDurationFromChannels() const { + if(_channels.empty()) + return 0; + double tmin = 1e5; double tmax = -1e5; ChannelList::const_iterator chan; diff --git a/src/osgAnimation/Channel.cpp b/src/osgAnimation/Channel.cpp index 3b1c3c5e7..17bc215b2 100644 --- a/src/osgAnimation/Channel.cpp +++ b/src/osgAnimation/Channel.cpp @@ -17,7 +17,7 @@ using namespace osgAnimation; Channel::Channel() {} Channel::~Channel() {} -Channel::Channel(const Channel& channel) : osg::Referenced(channel), +Channel::Channel(const Channel& channel) : osg::Object(channel), _targetName(channel._targetName), _name(channel._name) { diff --git a/src/osgAnimation/MorphGeometry.cpp b/src/osgAnimation/MorphGeometry.cpp index b22879072..88c40b56f 100644 --- a/src/osgAnimation/MorphGeometry.cpp +++ b/src/osgAnimation/MorphGeometry.cpp @@ -14,6 +14,7 @@ #include #include +#include #include @@ -63,124 +64,133 @@ void MorphGeometry::transformSoftwareMethod() osg::Geometry* morphGeometry = this; osg::Vec3Array* pos = dynamic_cast(morphGeometry->getVertexArray()); - if (pos && _positionSource.size() != pos->size()) - { - _positionSource = std::vector(pos->begin(),pos->end()); - pos->setDataVariance(osg::Object::DYNAMIC); - } - osg::Vec3Array* normal = dynamic_cast(morphGeometry->getNormalArray()); - if (normal && _normalSource.size() != normal->size()) + if(pos) { - _normalSource = std::vector(normal->begin(),normal->end()); - normal->setDataVariance(osg::Object::DYNAMIC); - } - - - if (!_positionSource.empty()) - { - bool initialized = false; - if (_method == NORMALIZED) + if ( _positionSource.size() != pos->size()) { - // base * 1 - (sum of weights) + sum of (weight * target) - float baseWeight = 0; - for (unsigned int i=0; i < _morphTargets.size(); i++) - { - baseWeight += _morphTargets[i].getWeight(); - } - baseWeight = 1 - baseWeight; + _positionSource = std::vector(pos->begin(),pos->end()); + pos->setDataVariance(osg::Object::DYNAMIC); + } - if (baseWeight != 0) + osg::Vec3Array* normal = dynamic_cast(morphGeometry->getNormalArray()); + bool normalmorphable = _morphNormals && normal; + if (normal && _normalSource.size() != normal->size()) + { + _normalSource = std::vector(normal->begin(),normal->end()); + normal->setDataVariance(osg::Object::DYNAMIC); + } + + + if (!_positionSource.empty()) + { + bool initialized = false; + if (_method == NORMALIZED) { + // base * 1 - (sum of weights) + sum of (weight * target) + float baseWeight = 0; + for (unsigned int i=0; i < _morphTargets.size(); i++) + { + baseWeight += _morphTargets[i].getWeight(); + } + baseWeight = 1 - baseWeight; + + if (baseWeight != 0) + { + initialized = true; + for (unsigned int i=0; i < pos->size(); i++) + { + (*pos)[i] = _positionSource[i] * baseWeight; + } + if (normalmorphable) + { + for (unsigned int i=0; i < normal->size(); i++) + { + (*normal)[i] = _normalSource[i] * baseWeight; + } + } + } + } + else //if (_method == RELATIVE) + { + // base + sum of (weight * target) initialized = true; for (unsigned int i=0; i < pos->size(); i++) { - (*pos)[i] = _positionSource[i] * baseWeight; + (*pos)[i] = _positionSource[i]; } - if (_morphNormals) + if (normalmorphable) { for (unsigned int i=0; i < normal->size(); i++) { - (*normal)[i] = _normalSource[i] * baseWeight; + (*normal)[i] = _normalSource[i]; } } } - } - else //if (_method == RELATIVE) - { - // base + sum of (weight * target) - initialized = true; - for (unsigned int i=0; i < pos->size(); i++) + + for (unsigned int i=0; i < _morphTargets.size(); i++) { - (*pos)[i] = _positionSource[i]; - } - if (_morphNormals) - { - for (unsigned int i=0; i < normal->size(); i++) + if (_morphTargets[i].getWeight() > 0) { - (*normal)[i] = _normalSource[i]; - } - } - } + // See if any the targets use the internal optimized geometry + osg::Geometry* targetGeometry = _morphTargets[i].getGeometry(); - for (unsigned int i=0; i < _morphTargets.size(); i++) - { - if (_morphTargets[i].getWeight() > 0) - { - // See if any the targets use the internal optimized geometry - osg::Geometry* targetGeometry = _morphTargets[i].getGeometry(); - - osg::Vec3Array* targetPos = dynamic_cast(targetGeometry->getVertexArray()); - osg::Vec3Array* targetNormals = dynamic_cast(targetGeometry->getNormalArray()); - - if (initialized) - { - // If vertices are initialized, add the morphtargets - for (unsigned int j=0; j < pos->size(); j++) + osg::Vec3Array* targetPos = dynamic_cast(targetGeometry->getVertexArray()); + osg::Vec3Array* targetNormals = dynamic_cast(targetGeometry->getNormalArray()); + normalmorphable = normalmorphable && targetNormals; + if(targetPos) { - (*pos)[j] += (*targetPos)[j] * _morphTargets[i].getWeight(); - } - - if (_morphNormals) - { - for (unsigned int j=0; j < normal->size(); j++) + if (initialized) { - (*normal)[j] += (*targetNormals)[j] * _morphTargets[i].getWeight(); + // If vertices are initialized, add the morphtargets + for (unsigned int j=0; j < pos->size(); j++) + { + (*pos)[j] += (*targetPos)[j] * _morphTargets[i].getWeight(); + } + + if (normalmorphable) + { + for (unsigned int j=0; j < normal->size(); j++) + { + (*normal)[j] += (*targetNormals)[j] * _morphTargets[i].getWeight(); + } + } } - } - } - else - { - // If not initialized, initialize with this morph target - initialized = true; - for (unsigned int j=0; j < pos->size(); j++) - { - (*pos)[j] = (*targetPos)[j] * _morphTargets[i].getWeight(); - } - - if (_morphNormals) - { - for (unsigned int j=0; j < normal->size(); j++) + else { - (*normal)[j] = (*targetNormals)[j] * _morphTargets[i].getWeight(); + // If not initialized, initialize with this morph target + initialized = true; + for (unsigned int j=0; j < pos->size(); j++) + { + (*pos)[j] = (*targetPos)[j] * _morphTargets[i].getWeight(); + } + + if (normalmorphable) + { + for (unsigned int j=0; j < normal->size(); j++) + { + (*normal)[j] = (*targetNormals)[j] * _morphTargets[i].getWeight(); + } + } } } } } + + pos->dirty(); + if (normalmorphable) + { + for (unsigned int j=0; j < normal->size(); j++) + { + (*normal)[j].normalize(); + } + normal->dirty(); + } } - pos->dirty(); - if (_morphNormals) - { - for (unsigned int j=0; j < normal->size(); j++) - { - (*normal)[j].normalize(); - } - normal->dirty(); - } + dirtyBound(); + } - - dirtyBound(); _dirty = false; } } @@ -206,7 +216,12 @@ void UpdateMorph::operator()(osg::Node* node, osg::NodeVisitor* nv) unsigned int numDrawables = geode->getNumDrawables(); for (unsigned int i = 0; i != numDrawables; ++i) { - osgAnimation::MorphGeometry* morph = dynamic_cast(geode->getDrawable(i)); + osg::Drawable *drw = geode->getDrawable(i); + osgAnimation::RigGeometry *rig = dynamic_cast(drw); + if(rig && rig->getSourceGeometry()) + drw = rig->getSourceGeometry(); + + osgAnimation::MorphGeometry* morph = dynamic_cast(drw); if (morph) { // Update morph weights diff --git a/src/osgAnimation/RigGeometry.cpp b/src/osgAnimation/RigGeometry.cpp index 8fc283017..522bad1b7 100644 --- a/src/osgAnimation/RigGeometry.cpp +++ b/src/osgAnimation/RigGeometry.cpp @@ -24,7 +24,7 @@ osg::BoundingBox RigComputeBoundingBoxCallback::computeBound(const osg::Drawable { const osgAnimation::RigGeometry& rig = dynamic_cast(drawable); - // if a valid initial bounding box is set we use it without asking more + // if a valid inital bounding box is set we use it without asking more if (rig.getInitialBound().valid()) return rig.getInitialBound(); @@ -32,7 +32,7 @@ osg::BoundingBox RigComputeBoundingBoxCallback::computeBound(const osg::Drawable return _boundingBox; // if the computing of bb is invalid (like no geometry inside) - // then don't tag the bounding box as computed + // then dont tag the bounding box as computed osg::BoundingBox bb = rig.computeBoundingBox(); if (!bb.valid()) return bb; @@ -58,8 +58,7 @@ RigGeometry::RigGeometry() _needToComputeMatrix = true; _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); - // disable the computation of boundingbox for the rig mesh - setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); + } @@ -70,8 +69,8 @@ RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) : _vertexInfluenceMap(b._vertexInfluenceMap), _needToComputeMatrix(b._needToComputeMatrix) { - // we don't copy the RigImplementation yet. because the RigImplementation need to be initialized in a valid graph, with a skeleton ... - // don't know yet what to do with a clone of a RigGeometry + // we dont copy the RigImplementation yet. because the RigImplementation need to be initialized in a valid graph, with a skeleton ... + // dont know yet what to do with a clone of a RigGeometry } @@ -113,7 +112,9 @@ void RigGeometry::computeMatrixFromRootSkeleton() osg::Matrix notRoot = _root->getMatrix(); _matrixFromSkeletonToGeometry = mtxList[0] * osg::Matrix::inverse(notRoot); _invMatrixFromSkeletonToGeometry = osg::Matrix::inverse(_matrixFromSkeletonToGeometry); - _needToComputeMatrix = false; + _needToComputeMatrix = false; + // disable the computation of boundingbox for the rig mesh + setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); } void RigGeometry::update() diff --git a/src/osgAnimation/RigTransformHardware.cpp b/src/osgAnimation/RigTransformHardware.cpp index 6cbd5f270..45ee92273 100644 --- a/src/osgAnimation/RigTransformHardware.cpp +++ b/src/osgAnimation/RigTransformHardware.cpp @@ -66,8 +66,6 @@ int RigTransformHardware::getNumVertexes() const { return _nbVertexes;} bool RigTransformHardware::createPalette(int nbVertexes, BoneMap boneMap, const VertexInfluenceSet::VertexIndexToBoneWeightMap& vertexIndexToBoneWeightMap) { typedef std::map BoneNameCountMap; - typedef std::map BoneNamePaletteIndex; - BoneNamePaletteIndex bname2palette; BonePalette palette; BoneNameCountMap boneNameCountMap; @@ -76,32 +74,35 @@ bool RigTransformHardware::createPalette(int nbVertexes, BoneMap boneMap, const vertexIndexWeight.resize(nbVertexes); int maxBonePerVertex = 0; - for (VertexInfluenceSet::VertexIndexToBoneWeightMap::const_iterator vis_itr = vertexIndexToBoneWeightMap.begin(); vis_itr != vertexIndexToBoneWeightMap.end(); ++vis_itr) + for (VertexInfluenceSet::VertexIndexToBoneWeightMap::const_iterator it = vertexIndexToBoneWeightMap.begin(); it != vertexIndexToBoneWeightMap.end(); ++it) { - int vertexIndex = vis_itr->first; - const VertexInfluenceSet::BoneWeightList& boneWeightList = vis_itr->second; + int vertexIndex = it->first; + const VertexInfluenceSet::BoneWeightList& boneWeightList = it->second; int bonesForThisVertex = 0; for (VertexInfluenceSet::BoneWeightList::const_iterator it = boneWeightList.begin(); it != boneWeightList.end(); ++it) { const VertexInfluenceSet::BoneWeight& bw = *it; - if (boneNameCountMap.find(bw.getBoneName()) != boneNameCountMap.end()) + if(fabs(bw.getWeight()) > 1e-2) // dont use bone with weight too small { - boneNameCountMap[bw.getBoneName()]++; - bonesForThisVertex++; // count max number of bones per vertexes - vertexIndexWeight[vertexIndex].push_back(IndexWeightEntry(bname2palette[bw.getBoneName()],bw.getWeight())); - } - else if (fabs(bw.getWeight()) > 1e-2) // don't use bone with weight too small - { - if (boneMap.find(bw.getBoneName()) == boneMap.end()) + if (boneNameCountMap.find(bw.getBoneName()) != boneNameCountMap.end()) { - OSG_INFO << "RigTransformHardware::createPalette can't find bone " << bw.getBoneName() << " skip this influence" << std::endl; - continue; + boneNameCountMap[bw.getBoneName()]++; + bonesForThisVertex++; // count max number of bones per vertexes + vertexIndexWeight[vertexIndex].push_back(IndexWeightEntry(_boneNameToPalette[bw.getBoneName()],bw.getWeight())); + } + else + { + if (boneMap.find(bw.getBoneName()) == boneMap.end()) + { + OSG_INFO << "RigTransformHardware::createPalette can't find bone " << bw.getBoneName() << " skip this influence" << std::endl; + continue; + } + boneNameCountMap[bw.getBoneName()] = 1; // for stats + bonesForThisVertex++; + palette.push_back(boneMap[bw.getBoneName()]); + _boneNameToPalette[bw.getBoneName()] = palette.size()-1; + vertexIndexWeight[vertexIndex].push_back(IndexWeightEntry(_boneNameToPalette[bw.getBoneName()],bw.getWeight())); } - boneNameCountMap[bw.getBoneName()] = 1; // for stats - bonesForThisVertex++; - palette.push_back(boneMap[bw.getBoneName()]); - bname2palette[bw.getBoneName()] = palette.size()-1; - vertexIndexWeight[vertexIndex].push_back(IndexWeightEntry(bname2palette[bw.getBoneName()],bw.getWeight())); } else { diff --git a/src/osgAnimation/RigTransformSoftware.cpp b/src/osgAnimation/RigTransformSoftware.cpp index ec64fb662..450c013d7 100644 --- a/src/osgAnimation/RigTransformSoftware.cpp +++ b/src/osgAnimation/RigTransformSoftware.cpp @@ -59,47 +59,53 @@ void RigTransformSoftware::operator()(RigGeometry& geom) osg::Vec3Array* positionSrc = dynamic_cast(source.getVertexArray()); osg::Vec3Array* positionDst = dynamic_cast(destination.getVertexArray()); - if (positionSrc && (!positionDst || (positionDst->size() != positionSrc->size()) ) ) + if (positionSrc ) { - if (!positionDst) + if (!positionDst || (positionDst->size() != positionSrc->size()) ) { - positionDst = new osg::Vec3Array; - positionDst->setDataVariance(osg::Object::DYNAMIC); - destination.setVertexArray(positionDst); + if (!positionDst) + { + positionDst = new osg::Vec3Array; + positionDst->setDataVariance(osg::Object::DYNAMIC); + destination.setVertexArray(positionDst); + } + *positionDst = *positionSrc; } - *positionDst = *positionSrc; + if (positionDst && !positionDst->empty()) + { + compute(geom.getMatrixFromSkeletonToGeometry(), + geom.getInvMatrixFromSkeletonToGeometry(), + &positionSrc->front(), + &positionDst->front()); + positionDst->dirty(); + } + } osg::Vec3Array* normalSrc = dynamic_cast(source.getNormalArray()); osg::Vec3Array* normalDst = dynamic_cast(destination.getNormalArray()); - if (normalSrc && (!normalDst || (normalDst->size() != normalSrc->size()) ) ) + if (normalSrc ) { - if (!normalDst) + if (!normalDst || (normalDst->size() != normalSrc->size()) ) { - normalDst = new osg::Vec3Array; - normalDst->setDataVariance(osg::Object::DYNAMIC); - destination.setNormalArray(normalDst, osg::Array::BIND_PER_VERTEX); + if (!normalDst) + { + normalDst = new osg::Vec3Array; + normalDst->setDataVariance(osg::Object::DYNAMIC); + destination.setNormalArray(normalDst, osg::Array::BIND_PER_VERTEX); + } + *normalDst = *normalSrc; + } + if (normalDst && !normalDst->empty()) + { + computeNormal(geom.getMatrixFromSkeletonToGeometry(), + geom.getInvMatrixFromSkeletonToGeometry(), + &normalSrc->front(), + &normalDst->front()); + normalDst->dirty(); } - *normalDst = *normalSrc; } - if (positionDst && !positionDst->empty()) - { - compute(geom.getMatrixFromSkeletonToGeometry(), - geom.getInvMatrixFromSkeletonToGeometry(), - &positionSrc->front(), - &positionDst->front()); - positionDst->dirty(); - } - - if (normalDst && !normalDst->empty()) - { - computeNormal(geom.getMatrixFromSkeletonToGeometry(), - geom.getInvMatrixFromSkeletonToGeometry(), - &normalSrc->front(), - &normalDst->front()); - normalDst->dirty(); - } } void RigTransformSoftware::initVertexSetFromBones(const BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence) @@ -120,9 +126,12 @@ void RigTransformSoftware::initVertexSetFromBones(const BoneMap& map, const Vert const std::string& bname = inf.getBones()[b].getBoneName(); float weight = inf.getBones()[b].getWeight(); BoneMap::const_iterator it = map.find(bname); - if (it == map.end()) + if (it == map.end() ) { - OSG_WARN << "RigTransformSoftware Bone " << bname << " not found, skip the influence group " <second.get(); diff --git a/src/osgAnimation/StackedRotateAxisElement.cpp b/src/osgAnimation/StackedRotateAxisElement.cpp index 7285fd2b2..cc8ea3264 100644 --- a/src/osgAnimation/StackedRotateAxisElement.cpp +++ b/src/osgAnimation/StackedRotateAxisElement.cpp @@ -18,7 +18,7 @@ using namespace osgAnimation; StackedRotateAxisElement::StackedRotateAxisElement(const std::string& name, const osg::Vec3& axis, double angle) : StackedTransformElement(), _axis(axis), _angle(angle) { setName(name); } StackedRotateAxisElement::StackedRotateAxisElement(const osg::Vec3& axis, double angle) : _axis(axis), _angle(angle) { setName("rotateaxis"); } -StackedRotateAxisElement::StackedRotateAxisElement() {} +StackedRotateAxisElement::StackedRotateAxisElement() : _axis(osg::Vec3(1,0,0)), _angle(0) {} StackedRotateAxisElement::StackedRotateAxisElement(const StackedRotateAxisElement& rhs, const osg::CopyOp&) : StackedTransformElement(rhs), _axis(rhs._axis), _angle(rhs._angle) { if (rhs._target.valid()) diff --git a/src/osgAnimation/StackedTransform.cpp b/src/osgAnimation/StackedTransform.cpp index 9be0a4652..a56b35f1a 100644 --- a/src/osgAnimation/StackedTransform.cpp +++ b/src/osgAnimation/StackedTransform.cpp @@ -18,8 +18,7 @@ using namespace osgAnimation; StackedTransform::StackedTransform() {} -StackedTransform::StackedTransform(const StackedTransform& rhs, const osg::CopyOp& co): - inherited(rhs) +StackedTransform::StackedTransform(const StackedTransform& rhs, const osg::CopyOp& co) { reserve(rhs.size()); for (StackedTransform::const_iterator it = rhs.begin(); it != rhs.end(); ++it) diff --git a/src/osgAnimation/StatsHandler.cpp b/src/osgAnimation/StatsHandler.cpp index d2ce73c4a..a62a167ec 100644 --- a/src/osgAnimation/StatsHandler.cpp +++ b/src/osgAnimation/StatsHandler.cpp @@ -90,6 +90,7 @@ struct StatsGraph : public osg::MatrixTransform void changeYposition(float y) { + osg::Vec3 _pos = getMatrix().getTrans(); _pos[1] = y - _height; setMatrix(osg::Matrix::translate(_pos)); } @@ -201,7 +202,7 @@ struct StatsGraph : public osg::MatrixTransform // Create primitive set if none exists. if (geometry->getNumPrimitiveSets() == 0) geometry->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, 0)); - osg::DrawArrays* drawArrays = dynamic_cast(geometry->getPrimitiveSet(0)); + osg::DrawArrays* drawArrays = static_cast(geometry->getPrimitiveSet(0)); drawArrays->setFirst(0); drawArrays->setCount(vertices->size()); } @@ -286,7 +287,7 @@ struct ValueTextDrawCallback : public virtual osg::Drawable::DrawCallback std::string _name; osg::ref_ptr _group; osg::ref_ptr _label; - osg::ref_ptr _graph; + osg::ref_ptr _graph; osg::ref_ptr _textLabel; osgAnimation::OutCubicMotion _fade; @@ -444,7 +445,7 @@ struct ValueTextDrawCallback : public virtual osg::Drawable::DrawCallback } pos.y() -= backgroundMargin; - osg::Vec3Array* array = dynamic_cast(_background->getVertexArray()); + osg::Vec3Array* array = static_cast(_background->getVertexArray()); float y = (*array)[0][1]; y = y - (pos.y() + backgroundMargin); //(2 * backgroundMargin + (size.size() * (characterSize + graphSpacing))); (*array)[1][1] = pos.y(); @@ -482,6 +483,9 @@ StatsHandler::StatsHandler(): _keyEventPrintsOutStats('A'), _statsType(NO_STATS), _initialized(false), + _frameRateChildNum(0), + _numBlocks(0), + _blockMultiplier(double(1.0)), _statsWidth(1280.0f), _statsHeight(1024.0f) { @@ -497,7 +501,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap osgViewer::Viewer* viewer = dynamic_cast(myview->getViewerBase()); - if (!viewer->getSceneData()) + if (!viewer || !viewer->getSceneData()) return false; if (ea.getHandled()) return false; @@ -621,7 +625,8 @@ void StatsHandler::setUpHUDCamera(osgViewer::ViewerBase* viewer) _camera->setAllowEventFocus(false); _camera->setCullMask(0x1); osgViewer::Viewer* v = dynamic_cast(viewer); - v->getSceneData()->asGroup()->addChild(_camera.get()); + if(v) + v->getSceneData()->asGroup()->addChild(_camera.get()); _initialized = true; } @@ -688,12 +693,11 @@ void StatAction::init(osg::Stats* stats, const std::string& name, const osg::Vec void StatAction::setAlpha(float v) { std::cout << this << " color alpha " << v << std::endl; - StatsGraph* gfx = dynamic_cast(_graph.get()); osg::Vec4 color = _textLabel->getColor(); color[3] = v; _textLabel->setColor(color); - for (int i = 0; i < (int) gfx->_statsGraphGeode->getNumDrawables(); i++) { - StatsGraph::Graph* g = dynamic_cast(gfx->_statsGraphGeode->getDrawable(0)); + for (int i = 0; i < (int) _graph->_statsGraphGeode->getNumDrawables(); i++) { + StatsGraph::Graph* g = static_cast(_graph->_statsGraphGeode->getDrawable(0)); g->setColor(color); } } @@ -701,12 +705,9 @@ void StatAction::setAlpha(float v) void StatAction::setPosition(const osg::Vec3& pos) { float characterSize = 20.0f; - StatsGraph* gfx = dynamic_cast(_graph.get()); - gfx->changeYposition(pos[1]); + _graph->changeYposition(pos[1]); _textLabel->setPosition(pos - osg::Vec3(0, characterSize,0)); - - } diff --git a/src/osgDB/StreamOperator.cpp b/src/osgDB/StreamOperator.cpp index 49ead30fb..a1ee9a749 100644 --- a/src/osgDB/StreamOperator.cpp +++ b/src/osgDB/StreamOperator.cpp @@ -16,6 +16,23 @@ using namespace osgDB; +static long long prev_tellg = 0; + +void InputIterator::checkStream() const +{ + if (_in->rdstate()&_in->failbit) + { + OSG_NOTICE<<"InputIterator::checkStream() : _in->rdstate() "<<_in->rdstate()<<", "<<_in->failbit<tellg() = "<<_in->tellg()< > KeyFrameCntr; + typedef osgAnimation::TemplateKeyframeContainer KeyFrameCntr; KeyFrameCntr eulerFrameCntr; readKeys(curveX, curveY, curveZ, defaultValue, eulerFrameCntr, static_cast(osg::PI / 180.0)); diff --git a/src/osgPlugins/fbx/fbxRMesh.cpp b/src/osgPlugins/fbx/fbxRMesh.cpp index d42d57abf..a60f6b3d1 100644 --- a/src/osgPlugins/fbx/fbxRMesh.cpp +++ b/src/osgPlugins/fbx/fbxRMesh.cpp @@ -413,7 +413,7 @@ void readAnimation(FbxNode* pNode, FbxScene& fbxScene, const std::string& target } osgAnimation::FloatLinearChannel* pChannel = new osgAnimation::FloatLinearChannel; - std::vector >& keyFrameCntr = *pChannel->getOrCreateSampler()->getOrCreateKeyframeContainer(); + osgAnimation::TemplateKeyframeContainer & keyFrameCntr = *pChannel->getOrCreateSampler()->getOrCreateKeyframeContainer(); for (int k = 0; k < nKeys; ++k) {