From b790986f3739db204dfdc1326ce426f34f6b0cc5 Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Thu, 31 Aug 2017 13:49:27 +0200 Subject: [PATCH] few cleanup --- include/osgAnimation/RigTransformHardware | 3 +++ src/osgAnimation/RigTransformHardware.cpp | 26 +++++++++++------------ src/osgAnimation/RigTransformSoftware.cpp | 1 - 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/osgAnimation/RigTransformHardware b/include/osgAnimation/RigTransformHardware index eeefa0030..5469fb299 100644 --- a/include/osgAnimation/RigTransformHardware +++ b/include/osgAnimation/RigTransformHardware @@ -62,8 +62,10 @@ namespace osgAnimation void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry); + // update rig if needed virtual void operator()(RigGeometry&); + // init animations data virtual bool prepareData(RigGeometry& ); protected: @@ -81,6 +83,7 @@ namespace osgAnimation unsigned int _minAttribIndex; bool buildPalette(const BoneMap& boneMap ,const RigGeometry& rig); + //on first update virtual bool init(RigGeometry& ); }; diff --git a/src/osgAnimation/RigTransformHardware.cpp b/src/osgAnimation/RigTransformHardware.cpp index 8713b5cef..85a32bdaa 100644 --- a/src/osgAnimation/RigTransformHardware.cpp +++ b/src/osgAnimation/RigTransformHardware.cpp @@ -21,13 +21,12 @@ using namespace osgAnimation; #define DEFAULT_FIRST_VERTATTRIB_TARGETTED 11 -RigTransformHardware::RigTransformHardware() -{ - _needInit = true; - _bonesPerVertex = 0; - _nbVertexes = 0; - _minAttribIndex = DEFAULT_FIRST_VERTATTRIB_TARGETTED; -} +RigTransformHardware::RigTransformHardware(): + _bonesPerVertex (0), + _nbVertexes (0), + _needInit (true), + _minAttribIndex(DEFAULT_FIRST_VERTATTRIB_TARGETTED) + {} RigTransformHardware::RigTransformHardware(const RigTransformHardware& rth, const osg::CopyOp& copyop): RigTransform(rth, copyop), @@ -152,8 +151,6 @@ bool RigTransformHardware::prepareData(RigGeometry& rig) // copy shallow from source geometry to rig rig.copyFrom(source); - - return true; } @@ -229,7 +226,6 @@ bool RigTransformHardware::buildPalette(const BoneMap&boneMap ,const RigGeometry OSG_INFO << "RigTransformHardware::buildPalette will use " << boneNameCountMap.size() * 4 << " uniforms" << std::endl; - } ///normalize @@ -251,16 +247,17 @@ bool RigTransformHardware::buildPalette(const BoneMap&boneMap ,const RigGeometry } } - _bonesPerVertex = maxBonePerVertex; _uniformMatrixPalette = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "matrixPalette", _bonePalette.size()); + _bonesPerVertex = maxBonePerVertex; + createVertexAttribList(*this,perVertexInfluences,this->_boneWeightAttribArrays); return true; } bool RigTransformHardware::init(RigGeometry& rig){ - if(_uniformMatrixPalette.valid()){ + if(_bonesPerVertex>0){ ///data seams prepared osg::ref_ptr program ; osg::ref_ptr vertexshader; @@ -328,14 +325,17 @@ bool RigTransformHardware::init(RigGeometry& rig){ program->addShader(vertexshader.get()); + stateset->removeUniform("nbBonesPerVertex"); stateset->addUniform(new osg::Uniform("nbBonesPerVertex",_bonesPerVertex)); + stateset->removeUniform("matrixPalette"); - stateset->addUniform(getMatrixPaletteUniform()); + stateset->addUniform(_uniformMatrixPalette); stateset->removeAttribute(osg::StateAttribute::PROGRAM); if(!stateset->getAttribute(osg::StateAttribute::PROGRAM)) stateset->setAttributeAndModes(program.get()); + _needInit = false; return false; } diff --git a/src/osgAnimation/RigTransformSoftware.cpp b/src/osgAnimation/RigTransformSoftware.cpp index 3e858647a..403033da3 100644 --- a/src/osgAnimation/RigTransformSoftware.cpp +++ b/src/osgAnimation/RigTransformSoftware.cpp @@ -70,7 +70,6 @@ void RigTransformSoftware::buildMinimumUpdateSet( const BoneMap&boneMap, const R const VertexIndexWeight &iw = *infit; const unsigned int &index = iw.getIndex(); float weight = iw.getWeight(); - perVertexInfluences[index].push_back(BonePtrWeight(bone, weight)); } }