opensurgsim
TangentSpaceGenerator.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_TANGENTSPACEGENERATOR_H
17 #define SURGSIM_GRAPHICS_TANGENTSPACEGENERATOR_H
18 
19 #include <osg/NodeVisitor>
20 #include <osg/Geode>
21 #include <osg/Geometry>
22 
23 namespace SurgSim
24 {
25 namespace Graphics
26 {
27 
31 {
32 public:
35 
39  void setBasisOrthonormality(bool orthonormal);
40 
44 
51  void set(const osg::Vec3Array* vertexArray,
52  const osg::Vec3Array* normalArray,
53  const osg::Vec2Array* textureCoordArray,
54  osg::Vec4Array* tangentArray,
55  osg::Vec4Array* bitangentArray);
56 
58  void orthogonalize();
59 
61  void reset();
62 
64  // space basis vectors.
68  void operator()(unsigned int vertexIndex1, unsigned int vertexIndex2, unsigned int vertexIndex3);
69 
70 private:
72  const osg::Vec3Array* m_vertexArray;
73 
75  const osg::Vec3Array* m_normalArray;
76 
78  const osg::Vec2Array* m_textureCoordArray;
79 
81  osg::Vec4Array* m_tangentArray;
82 
84  osg::Vec4Array* m_bitangentArray;
85 
88  bool m_createOrthonormalBasis;
89 };
90 
93 class TangentSpaceGenerator : public osg::NodeVisitor
94 {
95 public:
100  TangentSpaceGenerator(int textureCoordUnit, int tangentAttribIndex, int bitangentAttribIndex);
101 
103  virtual ~TangentSpaceGenerator();
104 
108  void setBasisOrthonormality(bool orthonormal);
109 
112  bool getBasisOrthonormality();
113 
116  void apply(osg::Geode& geode) override; // NOLINT
117 
125  static void generateTangentSpace(osg::Geometry* geometry,
126  int textureCoordUnit,
127  int tangentAttribIndex,
128  int bitangentAttribIndex,
129  bool orthonormal);
130 
131 private:
133  int m_textureCoordUnit;
134 
136  int m_tangentAttribIndex;
137 
139  int m_bitangentAttribIndex;
140 
143  bool m_createOrthonormalBasis;
144 };
145 
146 }
147 }
148 
149 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
bool getBasisOrthonormality()
Definition: TangentSpaceGenerator.cpp:82
void setBasisOrthonormality(bool orthonormal)
Sets whether the three tangent space basis vectors are made to be orthonormal; otherwise, each tangent is separately orthonormal to the normal, but not to each other.
Definition: TangentSpaceGenerator.cpp:78
Node visitor which calculates the tangent space basis vectors from the texture coordinates of any geo...
Definition: TangentSpaceGenerator.h:93
void operator()(unsigned int vertexIndex1, unsigned int vertexIndex2, unsigned int vertexIndex3)
Calculates the triangle tangent space basis vectors and adds it to each adjacent vertex&#39;s tangent...
Definition: TangentSpaceGenerator.cpp:141
void reset()
Resets all calculated tangent space basis vectors to 0.
Definition: TangentSpaceGenerator.cpp:130
void orthogonalize()
Orthogonalize and normalize the calculated tangent space basis vectors.
Definition: TangentSpaceGenerator.cpp:117
GenerateTangentSpaceTriangleIndexFunctor()
Constructor.
Definition: TangentSpaceGenerator.cpp:68
Triangle index functor which calculates the tangent space basis vectors for the vertices of a geometr...
Definition: TangentSpaceGenerator.h:30