This class is a callback for computing bump basis vectors on a given set of triangle/quad faces.
The callback could be used as an input parameter of the method ComputeMikkTangents to compute the tangent and binormal(bitangent). The Plug-ins need to implement GetNumberOfFaces, GetNumberVerticesOfFace, GetVertex, GetNormal and GetTexture methods to input all required data to be computed, and SetTangent method to output the computation results. Usage: The following code demostrates how to compute the MikkT tangents for a given triangle face.
{
public:
{
return 1;
}
{
return 3;
}
virtual void GetVertex(
Point3& position,
const int faceIdx,
const int vertIdx)
override
{
if (vertIdx ==0) {
position = { 0.0f, 0.0f, 0.0f };
}
else if (vertIdx==1) {
position = { 0.0f, 1.0f, 0.0f };
}
else if (vertIdx==2) {
position = { 1.0f, 0.0f, 0.0f };
}
}
virtual void GetNormal(
Point3& normal,
const int faceIdx,
const int vertIdx)
override
{
if (vertIdx == 0) {
normal = { 0.0f, 0.0f, 1.0f };
}
else if (vertIdx == 1) {
normal = { 0.0f, 0.0f, 1.0f };
}
else if (vertIdx == 2) {
normal = { 0.0f, 0.0f, 1.0f };
}
}
virtual void GetTexture(
Point2& texture,
const int faceIdx,
const int vertIdx)
override
{
if (vertIdx == 0) {
texture = { 0.0f, 0.0f };
}
else if (vertIdx == 1) {
texture = { 0.0f, 1.0f };
}
else if (vertIdx == 2) {
texture = { 1.0f, 0.0f };
}
}
const float handedness, const int faceIdx, const int vertIdx) override
{
outputTangents.Append(1, &tan);
outputBinormals.Append(1, &binml);
float hand = handedness;
outputHandednesses.Append(1, &hand);
}
return outputTangents;
}
return outputBinormals;
}
return outputHandednesses;
}
private:
};
TangentsComputationCallback cb;
Tab<float> handednesses = cb.GetHandednessesResult();
This class is a callback for computing bump basis vectors on a given set of triangle/quad faces.
Definition: gutil.h:242
virtual void GetTexture(Point2 &texture, const int faceIndex, const int vertexIndex)=0
Get the texture coordinates for the given index of face and index of vertex.
virtual void SetTangent(const Point3 &tangent, const Point3 &binormal, const float handedness, const int faceIndex, const int vertexIndex)=0
Set the tangent and binormal(bitangent) coordinates for the given index of face and index of vertex.
virtual int GetNumberOfFaces() const =0
Get the number of faces to be computed.
virtual int GetNumberVerticesOfFace(const int faceIndex) const =0
Get the number of vertices for the given index of face.
virtual void GetVertex(Point3 &vertex, const int faceIndex, const int vertexIndex)=0
Get the vertex coordinates for the given index of face and index of vertex.
virtual void GetNormal(Point3 &normal, const int faceIndex, const int vertexIndex)=0
Get the normal coordinates for the given index of face and index of vertex.
void ComputeMikkTangents(ITangentsComputationCallback *tangentsComputationCallback)
Computes the bump basis vector in MikkT way for the U texture channel (called the tangent),...