diff --git a/include/osgAnimation/MorphGeometry b/include/osgAnimation/MorphGeometry index f1401b6b1..ab6c1bc8f 100644 --- a/include/osgAnimation/MorphGeometry +++ b/include/osgAnimation/MorphGeometry @@ -29,7 +29,8 @@ namespace osgAnimation public: - enum Method { + enum Method + { NORMALIZED, RELATIVE }; @@ -61,7 +62,7 @@ namespace osgAnimation virtual const char* className() const { return "MorphGeometry"; } // set implementation of rig method - inline void setMorphTransformImplementation(MorphTransform*mt) { _morphTransformImplementation=mt; } + inline void setMorphTransformImplementation(MorphTransform*mt) { _morphTransformImplementation=mt; } inline MorphTransform* getMorphTransformImplementation() { return _morphTransformImplementation.get(); } inline const MorphTransform* getMorphTransformImplementation() const { return _morphTransformImplementation.get(); } @@ -88,16 +89,16 @@ namespace osgAnimation inline MorphTarget& getMorphTarget( unsigned int i ) { return _morphTargets[i]; } /** Set source of vertices for this morph geometry */ - inline void setVertexSource(osg::Vec3Array *v){ _positionSource=v;} + inline void setVertexSource(osg::Vec3Array *v) { _positionSource=v; } /** Get source of vertices for this morph geometry */ - inline osg::Vec3Array * getVertexSource()const{return _positionSource.get();} + inline osg::Vec3Array * getVertexSource() const { return _positionSource.get(); } /** Set source of normals for this morph geometry */ - inline void setNormalSource(osg::Vec3Array *n){ _normalSource=n;} + inline void setNormalSource(osg::Vec3Array *n) { _normalSource=n; } /** Get source of normals for this morph geometry */ - inline osg::Vec3Array * getNormalSource() const {return _normalSource.get();} + inline osg::Vec3Array * getNormalSource() const { return _normalSource.get(); } /** Add a \c MorphTarget to the \c MorphGeometry. * If \c MorphTarget is not \c NULL and is not contained in the \c MorphGeometry @@ -108,20 +109,30 @@ namespace osgAnimation * @param weight The weight to be added to the \c MorphGeometry. * @return \c true for success; \c false otherwise. */ - virtual void addMorphTarget( osg::Geometry *morphTarget, float weight = 1.0 ) { _morphTargets.push_back(MorphTarget(morphTarget, weight)); _dirty = true; } + virtual void addMorphTarget( osg::Geometry *morphTarget, float weight = 1.0 ) + { + _morphTargets.push_back(MorphTarget(morphTarget, weight)); + _dirty = true; + } - virtual void removeMorphTarget( osg::Geometry *morphTarget ) { - for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) { - if(iterator->getGeometry() == morphTarget) { + virtual void removeMorphTarget( osg::Geometry *morphTarget ) + { + for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) + { + if(iterator->getGeometry() == morphTarget) + { _morphTargets.erase(iterator); break; } } } - virtual void removeMorphTarget( const std::string& name ) { - for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) { - if(iterator->getGeometry() && iterator->getGeometry()->getName() == name) { + virtual void removeMorphTarget( const std::string& name ) + { + for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) + { + if(iterator->getGeometry() && iterator->getGeometry()->getName() == name) + { _morphTargets.erase(iterator); break; } @@ -141,10 +152,10 @@ namespace osgAnimation /** Set the MorphGeometry dirty.*/ inline void dirty(bool b=true) { _dirty = b; } - inline bool isDirty()const { return _dirty; } + inline bool isDirty() const { return _dirty; } /** for retrocompatibility */ - void transformSoftwareMethod(){(*_morphTransformImplementation.get())(*this);} + void transformSoftwareMethod() { (*_morphTransformImplementation.get())(*this); } protected: osg::ref_ptr _morphTransformImplementation; @@ -175,7 +186,8 @@ namespace osgAnimation void addTarget(const std::string& name) { _targetNames.push_back(name); } unsigned int getNumTarget() const { return _targetNames.size(); } const std::string& getTargetName(unsigned int index) { return _targetNames[index]; } - void removeTarget(const std::string& name) { + void removeTarget(const std::string& name) + { TargetNames::iterator found = std::find(_targetNames.begin(), _targetNames.end(), name); if(found != _targetNames.end()) _targetNames.erase(found); @@ -185,9 +197,7 @@ namespace osgAnimation const std::vector& getTargetNames() const { return _targetNames; } std::vector& getTargetNames() { return _targetNames; } - void setTargetNames(const TargetNames& targetNames) { - _targetNames.assign(targetNames.begin(), targetNames.end()); - } + void setTargetNames(const TargetNames& targetNames) { _targetNames.assign(targetNames.begin(), targetNames.end()); } /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); @@ -226,8 +236,6 @@ namespace osgAnimation (implementation)(*geom); } }; - - } #endif diff --git a/include/osgAnimation/MorphTransformHardware b/include/osgAnimation/MorphTransformHardware index bc0eebe8b..838fc99cf 100644 --- a/include/osgAnimation/MorphTransformHardware +++ b/include/osgAnimation/MorphTransformHardware @@ -42,19 +42,18 @@ namespace osgAnimation virtual void operator()(MorphGeometry&); - inline void setShader( osg::Shader*s ) { _shader=s; } - inline const osg::Shader * getShader() const{ return _shader.get(); } - inline osg::Shader * getShader() { return _shader.get(); } + inline void setShader( osg::Shader*s ) { _shader=s; } + inline const osg::Shader * getShader() const { return _shader.get(); } + inline osg::Shader * getShader() { return _shader.get(); } ///texture unit reserved for morphtarget TBO default is 7 - void setReservedTextureUnit(unsigned int t) { _reservedTextureUnit=t; } - unsigned int getReservedTextureUnit() const { return _reservedTextureUnit;} + void setReservedTextureUnit(unsigned int t) { _reservedTextureUnit=t; } + unsigned int getReservedTextureUnit() const { return _reservedTextureUnit; } protected: bool init(MorphGeometry&); - osg::ref_ptr _uniformTargetsWeight; osg::ref_ptr _shader; diff --git a/include/osgAnimation/MorphTransformSoftware b/include/osgAnimation/MorphTransformSoftware index 1130cdedc..50546501a 100644 --- a/include/osgAnimation/MorphTransformSoftware +++ b/include/osgAnimation/MorphTransformSoftware @@ -29,8 +29,8 @@ namespace osgAnimation class OSGANIMATION_EXPORT MorphTransformSoftware : public MorphTransform { public: - MorphTransformSoftware():_needInit(true){} - MorphTransformSoftware(const MorphTransformSoftware& rts,const osg::CopyOp& copyop): MorphTransform(rts, copyop), _needInit(true){} + MorphTransformSoftware():_needInit(true) {} + MorphTransformSoftware(const MorphTransformSoftware& rts,const osg::CopyOp& copyop): MorphTransform(rts, copyop), _needInit(true) {} META_Object(osgAnimation,MorphTransformSoftware) diff --git a/include/osgAnimation/RigGeometry b/include/osgAnimation/RigGeometry index dc96c98f4..f9a2b1887 100644 --- a/include/osgAnimation/RigGeometry +++ b/include/osgAnimation/RigGeometry @@ -23,7 +23,6 @@ namespace osgAnimation { - // The idea is to compute a bounding box with a factor x of the first step we compute the bounding box class OSGANIMATION_EXPORT RigComputeBoundingBoxCallback : public osg::Drawable::ComputeBoundingBoxCallback { @@ -37,8 +36,8 @@ namespace osgAnimation META_Object(osgAnimation, RigComputeBoundingBoxCallback); - void reset() { _computed = false; } + virtual osg::BoundingBox computeBound(const osg::Drawable& drawable) const; protected: mutable bool _computed; @@ -58,16 +57,16 @@ namespace osgAnimation META_Object(osgAnimation, RigGeometry); inline void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; } - inline const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();} - inline VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();} + inline const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get(); } + inline VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get(); } inline const Skeleton* getSkeleton() const { return _root.get(); } inline Skeleton* getSkeleton() { return _root.get(); } // will be used by the update callback to init correctly the rig mesh - inline void setSkeleton(Skeleton* root){ _root = root;} + inline void setSkeleton(Skeleton* root) { _root = root; } - void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;} - bool getNeedToComputeMatrix() const { return _needToComputeMatrix;} + void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state; } + bool getNeedToComputeMatrix() const { return _needToComputeMatrix; } void computeMatrixFromRootSkeleton(); @@ -78,9 +77,10 @@ namespace osgAnimation void update(); - void buildVertexInfluenceSet(){_rigTransformImplementation->prepareData(*this);} + void buildVertexInfluenceSet() { _rigTransformImplementation->prepareData(*this); } const osg::Matrix& getMatrixFromSkeletonToGeometry() const; + const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const; inline osg::Geometry* getSourceGeometry() { return _geometry.get(); } @@ -106,7 +106,6 @@ namespace osgAnimation osg::ref_ptr _geometry; osg::ref_ptr _rigTransformImplementation; - osg::ref_ptr _vertexInfluenceMap; osg::Matrix _matrixFromSkeletonToGeometry; @@ -114,8 +113,7 @@ namespace osgAnimation osg::observer_ptr _root; bool _needToComputeMatrix; - - }; + }; struct UpdateRigGeometry : public osg::Drawable::UpdateCallback @@ -129,7 +127,8 @@ namespace osgAnimation META_Object(osgAnimation, UpdateRigGeometry); - virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw) { + virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw) + { RigGeometry* geom = dynamic_cast(drw); if(!geom) return; @@ -155,7 +154,8 @@ namespace osgAnimation if(geom->getNeedToComputeMatrix()) geom->computeMatrixFromRootSkeleton(); - if(geom->getSourceGeometry()) { + if(geom->getSourceGeometry()) + { osg::Drawable::UpdateCallback * up = dynamic_cast(geom->getSourceGeometry()->getUpdateCallback()); if(up) up->update(nv, geom->getSourceGeometry()); diff --git a/include/osgAnimation/RigTransform b/include/osgAnimation/RigTransform index 9a6a0e367..ba41b8db1 100644 --- a/include/osgAnimation/RigTransform +++ b/include/osgAnimation/RigTransform @@ -1,15 +1,15 @@ - /* -*-c++-*- - * Copyright (C) 2009 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 - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. +/* -*-c++-*- +* Copyright (C) 2009 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 +* (at your option) any later version. The full license is in LICENSE file +* included with this distribution, and on the openscenegraph.org website. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* OpenSceneGraph Public License for more details. */ #ifndef OSGANIMATION_RIGTRANSFORM @@ -35,7 +35,7 @@ namespace osgAnimation /// to call manually when a skeleton is reacheable from the rig /// in order to prepare technic data before rendering - virtual bool prepareData(RigGeometry&){return true;} + virtual bool prepareData(RigGeometry&) { return true; } protected: virtual ~RigTransform() {} diff --git a/include/osgAnimation/RigTransformHardware b/include/osgAnimation/RigTransformHardware index c71f2ae16..5b020f4a4 100644 --- a/include/osgAnimation/RigTransformHardware +++ b/include/osgAnimation/RigTransformHardware @@ -46,22 +46,22 @@ namespace osgAnimation typedef std::vector MatrixPalette; ///set the first Vertex Attribute Array index of the rig generated by this technic (default:11) - void setFirstVertexAttributeTarget(unsigned int i){ _minAttribIndex=i;} - unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex;} + void setFirstVertexAttributeTarget(unsigned int i) { _minAttribIndex=i; } + unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex; } - void setShader(osg::Shader* shader) { _shader = shader; } - const osg::Shader* getShader() const { return _shader.get(); } - osg::Shader* getShader() { return _shader.get(); } + void setShader(osg::Shader* shader) { _shader = shader; } + const osg::Shader* getShader() const { return _shader.get(); } + osg::Shader* getShader() { return _shader.get(); } osg::Vec4Array* getVertexAttrib(unsigned int index); - unsigned int getNumVertexAttrib() const {return _boneWeightAttribArrays.size();} + unsigned int getNumVertexAttrib() const { return _boneWeightAttribArrays.size(); } - const unsigned int &getNumBonesPerVertex() const{ return _bonesPerVertex; } - const unsigned int &getNumVertexes() const { return _nbVertices; } + const unsigned int &getNumBonesPerVertex() const { return _bonesPerVertex; } + const unsigned int &getNumVertexes() const { return _nbVertices; } - const BoneNamePaletteIndex& getBoneNameToPalette(){ return _boneNameToPalette; } - const BonePalette& getBonePalette() { return _bonePalette; } - osg::Uniform* getMatrixPaletteUniform() { return _uniformMatrixPalette.get(); } + const BoneNamePaletteIndex& getBoneNameToPalette() { return _boneNameToPalette; } + const BonePalette& getBonePalette() { return _bonePalette; } + osg::Uniform* getMatrixPaletteUniform() { return _uniformMatrixPalette.get(); } void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry); @@ -84,7 +84,7 @@ namespace osgAnimation bool _needInit; unsigned int _minAttribIndex; - bool buildPalette(const BoneMap& boneMap ,const RigGeometry& rig); + bool buildPalette(const BoneMap& boneMap,const RigGeometry& rig); //on first update virtual bool init(RigGeometry& ); diff --git a/include/osgAnimation/RigTransformSoftware b/include/osgAnimation/RigTransformSoftware index 243c635d2..4424498ba 100644 --- a/include/osgAnimation/RigTransformSoftware +++ b/include/osgAnimation/RigTransformSoftware @@ -44,20 +44,20 @@ namespace osgAnimation class BonePtrWeight: LocalBoneIDWeight { public: - BonePtrWeight(unsigned int id,float weight, Bone*bone=0 ): LocalBoneIDWeight(id,weight), _boneptr(bone){} - BonePtrWeight(const BonePtrWeight &bw2): LocalBoneIDWeight(bw2.getBoneID(),bw2.getWeight()), _boneptr(bw2._boneptr.get()){} - inline const float & getWeight() const {return second;} - inline void setWeight(float b) {second=b;} - inline const unsigned int & getBoneID() const {return first;} - inline void setBoneID(unsigned int b) {first=b;} - inline bool operator<(const BonePtrWeight &b1) const{ - if (second > b1.second)return true; - if (second < b1.second)return false; - return (first > b1.first); + BonePtrWeight(unsigned int id,float weight, Bone*bone=0 ): LocalBoneIDWeight(id,weight), _boneptr(bone) {} + BonePtrWeight(const BonePtrWeight &bw2): LocalBoneIDWeight(bw2.getBoneID(),bw2.getWeight()), _boneptr(bw2._boneptr.get()) {} + inline const float & getWeight() const { return second; } + inline void setWeight(float b) { second=b; } + inline const unsigned int & getBoneID() const { return first; } + inline void setBoneID(unsigned int b) { first=b; } + inline bool operator< (const BonePtrWeight &b1) const { + if (second > b1.second) return true; + if (second < b1.second) return false; + return (first > b1.first); } ///set Bone pointer - inline const Bone * getBonePtr() const {return _boneptr.get();} - inline void setBonePtr(Bone*b){_boneptr=b;} + inline const Bone * getBonePtr() const { return _boneptr.get(); } + inline void setBonePtr(Bone*b) { _boneptr=b; } protected: osg::observer_ptr< Bone > _boneptr; }; @@ -110,7 +110,7 @@ namespace osgAnimation } resetMatrix(); - for(BonePtrWeightList::iterator bwit=_boneweights.begin();bwit!=_boneweights.end();++bwit ) + for(BonePtrWeightList::iterator bwit=_boneweights.begin(); bwit!=_boneweights.end(); ++bwit ) { const Bone* bone = bwit->getBonePtr(); if (!bone) @@ -125,7 +125,7 @@ namespace osgAnimation } } void normalize(); - inline const osg::Matrix& getMatrix() const { return _result;} + inline const osg::Matrix& getMatrix() const { return _result; } protected: BonePtrWeightList _boneweights; IndexList _vertexes; diff --git a/include/osgAnimation/VertexInfluence b/include/osgAnimation/VertexInfluence index eb2956b72..256d9c198 100644 --- a/include/osgAnimation/VertexInfluence +++ b/include/osgAnimation/VertexInfluence @@ -41,15 +41,14 @@ namespace osgAnimation class OSGANIMATION_EXPORT VertexInfluence : public IndexWeightList { public: - const std::string& getName() const { return _name;} - void setName(const std::string& name) { _name = name;} - + const std::string& getName() const { return _name; } + void setName(const std::string& name) { _name = name; } protected: // the name is the bone to link to std::string _name; }; - class VertexInfluenceMap : public std::map , public osg::Object + class VertexInfluenceMap : public std::map, public osg::Object { public: META_Object(osgAnimation, VertexInfluenceMap); @@ -57,8 +56,8 @@ namespace osgAnimation VertexInfluenceMap() {} VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop): std::map(org), - osg::Object(org, copyop) - {} + osg::Object(org, copyop) {} + ///normalize per vertex weights given numvert of the attached mesh void normalize(unsigned int numvert); @@ -72,8 +71,8 @@ namespace osgAnimation class VertexGroup: public std::pair { public: - inline const BoneWeightList& getBoneWeights()const { return first; } - inline void setBoneWeights( BoneWeightList& o ) { first=o; } + inline const BoneWeightList& getBoneWeights() const { return first; } + inline void setBoneWeights( BoneWeightList& o ) { first=o; } inline IndexList& vertIDs() { return second; } }; @@ -83,7 +82,6 @@ namespace osgAnimation //Experimental removal of unexpressed bone from the skeleton void removeUnexpressedBones(Skeleton &skel) const; }; - } #endif