TangentSpaceGenerator.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_TANGENTSPACEGENERATOR_H
#define SURGSIM_GRAPHICS_TANGENTSPACEGENERATOR_H
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/Geometry>
namespace SurgSim
{
namespace Graphics
{
class GenerateTangentSpaceTriangleIndexFunctor
{
public:
GenerateTangentSpaceTriangleIndexFunctor();
void setBasisOrthonormality(bool orthonormal);
bool getBasisOrthonormality();
void set(const osg::Vec3Array* vertexArray,
const osg::Vec3Array* normalArray,
const osg::Vec2Array* textureCoordArray,
osg::Vec4Array* tangentArray,
osg::Vec4Array* bitangentArray);
void orthogonalize();
void reset();
// space basis vectors.
void operator()(unsigned int vertexIndex1, unsigned int vertexIndex2, unsigned int vertexIndex3);
private:
const osg::Vec3Array* m_vertexArray;
const osg::Vec3Array* m_normalArray;
const osg::Vec2Array* m_textureCoordArray;
osg::Vec4Array* m_tangentArray;
osg::Vec4Array* m_bitangentArray;
bool m_createOrthonormalBasis;
};
class TangentSpaceGenerator : public osg::NodeVisitor
{
public:
TangentSpaceGenerator(int textureCoordUnit, int tangentAttribIndex, int bitangentAttribIndex);
virtual ~TangentSpaceGenerator();
void setBasisOrthonormality(bool orthonormal);
bool getBasisOrthonormality();
void apply(osg::Geode& geode) override; // NOLINT
static void generateTangentSpace(osg::Geometry* geometry,
int textureCoordUnit,
int tangentAttribIndex,
int bitangentAttribIndex,
bool orthonormal);
private:
int m_textureCoordUnit;
int m_tangentAttribIndex;
int m_bitangentAttribIndex;
bool m_createOrthonormalBasis;
};
}
}
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::TangentSpaceGenerator::m_createOrthonormalBasis
bool m_createOrthonormalBasis
Whether or not to create a fully orthonormal basis; otherwise, each tangent is separately orthonormal...
Definition: TangentSpaceGenerator.h:143
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::getBasisOrthonormality
bool getBasisOrthonormality()
Definition: TangentSpaceGenerator.cpp:81
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::setBasisOrthonormality
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:77
SurgSim::Graphics::TangentSpaceGenerator::m_tangentAttribIndex
int m_tangentAttribIndex
Index of the vertex attribute array to store the calculated tangents.
Definition: TangentSpaceGenerator.h:136
SurgSim::Graphics::TangentSpaceGenerator
Node visitor which calculates the tangent space basis vectors from the texture coordinates of any geo...
Definition: TangentSpaceGenerator.h:93
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::operator()
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:140
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::reset
void reset()
Resets all calculated tangent space basis vectors to 0.
Definition: TangentSpaceGenerator.cpp:129
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::orthogonalize
void orthogonalize()
Orthogonalize and normalize the calculated tangent space basis vectors.
Definition: TangentSpaceGenerator.cpp:116
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::GenerateTangentSpaceTriangleIndexFunctor
GenerateTangentSpaceTriangleIndexFunctor()
Constructor.
Definition: TangentSpaceGenerator.cpp:67
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_vertexArray
const osg::Vec3Array * m_vertexArray
Array containing vertex positions.
Definition: TangentSpaceGenerator.h:72
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_createOrthonormalBasis
bool m_createOrthonormalBasis
Whether or not to create a fully orthonormal basis; otherwise, each tangent is separately orthonormal...
Definition: TangentSpaceGenerator.h:88
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor
Triangle index functor which calculates the tangent space basis vectors for the vertices of a geometr...
Definition: TangentSpaceGenerator.h:30
SurgSim::Graphics::TangentSpaceGenerator::m_textureCoordUnit
int m_textureCoordUnit
Texture unit of texture coordinates to use for calculating the tangent space.
Definition: TangentSpaceGenerator.h:133
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_tangentArray
osg::Vec4Array * m_tangentArray
Array storing calculated tangents.
Definition: TangentSpaceGenerator.h:81
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_bitangentArray
osg::Vec4Array * m_bitangentArray
Array storing calculated bitangents.
Definition: TangentSpaceGenerator.h:84
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_textureCoordArray
const osg::Vec2Array * m_textureCoordArray
Array containing texture coordinates.
Definition: TangentSpaceGenerator.h:78
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_normalArray
const osg::Vec3Array * m_normalArray
Array containing normals.
Definition: TangentSpaceGenerator.h:75
SurgSim::Graphics::TangentSpaceGenerator::m_bitangentAttribIndex
int m_bitangentAttribIndex
Index of the vertex attribute array to store the calculated bitangents.
Definition: TangentSpaceGenerator.h:139