3ds Max C++ API Reference
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>

+ Inheritance diagram for ITangentsComputationCallback:

Public Member Functions

virtual int GetNumberOfFaces () const =0
 Get the number of faces to be computed. More...
 
virtual int GetNumberVerticesOfFace (const int faceIndex) const =0
 Get the number of vertices for the given index of face. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Protected Member Functions

virtual ~ITangentsComputationCallback ()
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

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
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.
Definition: point2.h:44
Definition: point3.h:56
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.