openscenegraph
RigTransformHardware
Go to the documentation of this file.
1/* -*-c++-*-
2 * Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
3 * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
4 *
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.
9 *
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.
14 */
15
16#ifndef OSGANIMATION_RIG_TRANSFORM_HARDWARE
17#define OSGANIMATION_RIG_TRANSFORM_HARDWARE 1
18
19#include <osgAnimation/Export>
20#include <osgAnimation/RigTransform>
21#include <osgAnimation/VertexInfluence>
22#include <osgAnimation/Bone>
23#include <osg/Matrix>
24#include <osg/Array>
25
26#define RIGTRANSHW_DEFAULT_FIRST_VERTATTRIB_TARGETTED 11
27
28namespace osgAnimation
29{
30 class RigGeometry;
31
32 /// This class manage format for hardware skinning
33 class OSGANIMATION_EXPORT RigTransformHardware : public RigTransform
34 {
35 public:
36
37 RigTransformHardware();
38
39 RigTransformHardware(const RigTransformHardware& rth, const osg::CopyOp& copyop);
40
41 META_Object(osgAnimation,RigTransformHardware);
42
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;
47
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; }
51
52 void setShader(osg::Shader* shader) { _shader = shader; }
53 const osg::Shader* getShader() const { return _shader.get(); }
54 osg::Shader* getShader() { return _shader.get(); }
55
56 osg::Vec4Array* getVertexAttrib(unsigned int index);
57 unsigned int getNumVertexAttrib() const { return _boneWeightAttribArrays.size(); }
58
59 const unsigned int &getNumBonesPerVertex() const { return _bonesPerVertex; }
60 const unsigned int &getNumVertexes() const { return _nbVertices; }
61
62 const BoneNamePaletteIndex& getBoneNameToPalette() { return _boneNameToPalette; }
63 const BonePalette& getBonePalette() { return _bonePalette; }
64 osg::Uniform* getMatrixPaletteUniform() { return _uniformMatrixPalette.get(); }
65
66 void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry);
67
68 // update rig if needed
69 virtual void operator()(RigGeometry&);
70
71 // init/reset animations data
72 virtual bool prepareData(RigGeometry& );
73
74 protected:
75
76 unsigned int _bonesPerVertex;
77 unsigned int _nbVertices;
78
79 BonePalette _bonePalette;
80 BoneNamePaletteIndex _boneNameToPalette;
81 BoneWeightAttribList _boneWeightAttribArrays;
82 osg::ref_ptr<osg::Uniform> _uniformMatrixPalette;
83 osg::ref_ptr<osg::Shader> _shader;
84
85 bool _needInit;
86 unsigned int _minAttribIndex;
87 bool buildPalette(const BoneMap& boneMap,const RigGeometry& rig);
88
89 //on first update
90 virtual bool init(RigGeometry& );
91
92 std::vector<IndexWeightList> _perVertexInfluences;
93 };
94}
95
96#endif