2 * Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
3 * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
5 * This library is open source and may be redistributed and/or modified under
6 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
7 * (at your option) any later version. The full license is in LICENSE file
8 * included with this distribution, and on the openscenegraph.org website.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * OpenSceneGraph Public License for more details.
16#ifndef OSGANIMATION_RIG_TRANSFORM_HARDWARE
17#define OSGANIMATION_RIG_TRANSFORM_HARDWARE 1
19#include <osgAnimation/Export>
20#include <osgAnimation/RigTransform>
21#include <osgAnimation/VertexInfluence>
22#include <osgAnimation/Bone>
26#define RIGTRANSHW_DEFAULT_FIRST_VERTATTRIB_TARGETTED 11
32 /// This class manage format for hardware skinning
33 class OSGANIMATION_EXPORT RigTransformHardware : public RigTransform
37 RigTransformHardware();
39 RigTransformHardware(const RigTransformHardware& rth, const osg::CopyOp& copyop);
41 META_Object(osgAnimation,RigTransformHardware);
43 typedef std::vector<osg::ref_ptr<osg::Vec4Array> > BoneWeightAttribList;
44 typedef std::vector<osg::ref_ptr<Bone> > BonePalette;
45 typedef std::map<std::string, unsigned int> BoneNamePaletteIndex;
46 typedef std::vector<osg::Matrix> MatrixPalette;
48 ///set the first Vertex Attribute Array index of the rig generated by this technic (default:11)
49 void setFirstVertexAttributeTarget(unsigned int i) { _minAttribIndex=i; }
50 unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex; }
52 void setShader(osg::Shader* shader) { _shader = shader; }
53 const osg::Shader* getShader() const { return _shader.get(); }
54 osg::Shader* getShader() { return _shader.get(); }
56 osg::Vec4Array* getVertexAttrib(unsigned int index);
57 unsigned int getNumVertexAttrib() const { return _boneWeightAttribArrays.size(); }
59 const unsigned int &getNumBonesPerVertex() const { return _bonesPerVertex; }
60 const unsigned int &getNumVertexes() const { return _nbVertices; }
62 const BoneNamePaletteIndex& getBoneNameToPalette() { return _boneNameToPalette; }
63 const BonePalette& getBonePalette() { return _bonePalette; }
64 osg::Uniform* getMatrixPaletteUniform() { return _uniformMatrixPalette.get(); }
66 void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry);
68 // update rig if needed
69 virtual void operator()(RigGeometry&);
71 // init/reset animations data
72 virtual bool prepareData(RigGeometry& );
76 unsigned int _bonesPerVertex;
77 unsigned int _nbVertices;
79 BonePalette _bonePalette;
80 BoneNamePaletteIndex _boneNameToPalette;
81 BoneWeightAttribList _boneWeightAttribArrays;
82 osg::ref_ptr<osg::Uniform> _uniformMatrixPalette;
83 osg::ref_ptr<osg::Shader> _shader;
86 unsigned int _minAttribIndex;
87 bool buildPalette(const BoneMap& boneMap,const RigGeometry& rig);
90 virtual bool init(RigGeometry& );
92 std::vector<IndexWeightList> _perVertexInfluences;