3ds Max C++ API Reference
Loading...
Searching...
No Matches
ITangentsComputationCallback Class Referenceabstract

This class is a callback for computing bump basis vectors on a given set of triangle/quad faces. More...

#include <gutil.h>

Public Member Functions

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.
 
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.
 

Protected Member Functions

virtual ~ITangentsComputationCallback ()
 

Detailed Description

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.

// Derive from ITangentsComputationCallback to fill the input data and receive the output results
class TangentsComputationCallback : public ITangentsComputationCallback
{
public:
// Return 1 for the case with only one face
virtual int GetNumberOfFaces() const override
{
return 1;
}
// Return the vertex number for the given face, 3 for triangle face, 4 for quad face
virtual int GetNumberVerticesOfFace(const int faceIdx) const override
{
return 3;
}
// Input the position coordinates for the given vertex specified by the index of face and vertex
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 };
}
}
// Input the normal coordinates for the given vertex specified by the index of face and vertex
virtual void GetNormal(Point3& normal, const int faceIdx, const int vertIdx) override
{
// Use the same normal coordinates { 0.0f, 0.0f, 1.0f } for all three vertices for simplicity
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 };
}
}
// Input the texture coordinates for the given vertex specified by the index of face and vertex
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 };
}
}
// Ouput the tangent, bitangent and handedness for the given vertex specified by the index of face and vertex
virtual void SetTangent(const Point3& tangent, const Point3& binormal,
const float handedness, const int faceIdx, const int vertIdx) override
{
// Set tangent
Point3 tan = tangent;
outputTangents.Append(1, &tan);
// Set binormal
Point3 binml = binormal;
outputBinormals.Append(1, &binml);
// Set handedness
float hand = handedness;
outputHandednesses.Append(1, &hand);
}
// Return the computation result of Tangents
Tab<Point3> GetTangentsResult() {
return outputTangents;
}
// Return the computation result of Binormals
Tab<Point3> GetBinormalsResult() {
return outputBinormals;
}
// Return the computation result of Handednesses
Tab<float> GetHandednessesResult() {
return outputHandednesses;
}
private:
// Output tangent/binormal data
Tab<Point3> outputTangents;
Tab<Point3> outputBinormals;
Tab<float> outputHandednesses;
};
// Compute tangent basis
TangentsComputationCallback cb;
// Get the computation results
Tab<Point3> tangents = cb.GetTangentsResult();
Tab<Point3> binormals = cb.GetBinormalsResult();
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
Definition: point2.h:38
Definition: point3.h:54
Generic container class.
Definition: tab.h:180
void ComputeMikkTangents(ITangentsComputationCallback *tangentsComputationCallback)
Computes the bump basis vector in MikkT way for the U texture channel (called the tangent),...

Constructor & Destructor Documentation

◆ ~ITangentsComputationCallback()

virtual ~ITangentsComputationCallback ( )
inlineprotectedvirtual
292 {
293 }

Member Function Documentation

◆ GetNumberOfFaces()

virtual int GetNumberOfFaces ( ) const
pure virtual

Get the number of faces to be computed.

Returns
The the number of faces to be computed.

◆ GetNumberVerticesOfFace()

virtual int GetNumberVerticesOfFace ( const int  faceIndex) const
pure virtual

Get the number of vertices for the given index of face.

Parameters
faceIndexThe index of the face.
Returns
The number of vertices for the given index of face.

◆ GetVertex()

virtual void GetVertex ( Point3 vertex,
const int  faceIndex,
const int  vertexIndex 
)
pure virtual

Get the vertex coordinates for the given index of face and index of vertex.

Parameters
[out]vertexThe vertex coordinates for the given index of face and index of vertex.
faceIndexThe index of the face.
vertexIndexThe index of the vertex based on the face.

◆ GetNormal()

virtual void GetNormal ( Point3 normal,
const int  faceIndex,
const int  vertexIndex 
)
pure virtual

Get the normal coordinates for the given index of face and index of vertex.

Parameters
[out]normalThe normal coordinates for the given index of face and index of vertex.
faceIndexThe index of the face.
vertexIndexThe index of the vertex based on the face.

◆ GetTexture()

virtual void GetTexture ( Point2 texture,
const int  faceIndex,
const int  vertexIndex 
)
pure virtual

Get the texture coordinates for the given index of face and index of vertex.

Parameters
[out]textureThe texture coordinates for the given index of face and index of vertex.
faceIndexThe index of the face.
vertexIndexThe index of the vertex based on the face.

◆ SetTangent()

virtual void SetTangent ( const Point3 tangent,
const Point3 binormal,
const float  handedness,
const int  faceIndex,
const int  vertexIndex 
)
pure virtual

Set the tangent and binormal(bitangent) coordinates for the given index of face and index of vertex.

Parameters
tangentThe tangent coordinates for the given index of face and index of vertex.
binormalThe binormal(bitangent) coordinates for the given index of face and index of vertex.
handednessThe handedness of tangent basis, either 1.0f or -1.0f. the handedness can be used to determine the direction of the binormal(bitangent), callers can use normal, tangent and handedness to re-calculate the binormal(bitangent) in pixel level, binormal(bitangent) = handedness * CrossProd(normal, tangent);
faceIndexThe index of the face.
vertexIndexThe index of the vertex based on the face.