3ds Max C++ API Reference
Loading...
Searching...
No Matches
gutil.h File Reference
#include "GeomExport.h"
#include "point2.h"
#include "point3.h"
#include "geom_span.hpp"
#include <cstdint>

Classes

class  ITangentsComputationCallback
 This class is a callback for computing bump basis vectors on a given set of triangle/quad faces. More...
 
struct  UVTangentVectors
 Return value of ComputeUVTangents(). More...
 

Functions

Point3 BaryCoords (Point3 p0, Point3 p1, Point3 p2, Point3 p)
 Calculates the barycentric coordinates of the point p in 3-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2.
 
Point3 BaryCoords (Point2 p0, Point2 p1, Point2 p2, Point2 p)
 Calculates the barycentric coordinates of the point p in 2-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2.
 
bool RayHitsBox (Ray &ray, Box3 &b)
 Checks if the given ray intersects a three-dimensional box.
 
float DistPtToLine (Point2 *p0, Point2 *p1, Point2 *q)
 Calculates the distance of a given point from a line in two dimensions.
 
float Dist3DPtToLine (Point3 *p0, Point3 *p1, Point3 *q)
 Calculates the distance of a given point from a line in three dimensions.
 
bool ComputeIntersectionPoint (Point3 &intersectionPoint, geo::span< const Point3 > fixedCoeffs, geo::span< const Point3 > directionVecs, bool doNormalize=true)
 Compute the point of intersection, or a least squares approximation to it, for an arbitrary number N of lines in three dimensions.
 
void ComputeBumpVectors (const Point3 tv[3], const Point3 v[3], Point3 bvec[3])
 
void ComputeBumpVec2D (int axis, const Point3 tv[3], const Point3 v[3], Point3 bvec[2])
 Computes the 2 Bump basis vectors from the UV, VW, or WU at a triangle.
 
Point3 ComputeTangent (const Point3 tv[3], const Point3 v[3])
 returns the bump basis vector for the U texture channel (called the tangent)
 
void ComputeTangentAndBinormal (const Point3 tv[3], const Point3 v[3], Point3 bvec[2])
 Computes the bump basis vector for the U texture channel (called the tangent), and the cross product of the surface normal with the tangent (called the binormal).
 
void ComputeMikkTangents (ITangentsComputationCallback *tangentsComputationCallback)
 Computes the bump basis vector in MikkT way for the U texture channel (called the tangent), and the cross product of the surface normal with the tangent (called the binormal).
 
UVTangentVectors ComputeUVTangents (const Point3 &p0, const Point3 &p1, const Point3 &p2, const Point2 &uv0, const Point2 &uv1, const Point2 &uv2)
 Computes the bump basis vectors for the U and V components of the texture coordinates channel (also called the tangent and bitangent).
 
uint32_t CompressNormal (Point3 p)
 Low precision compression of a vector from 12 bytes to 4 bytes.
 
Point3 DeCompressNormal (uint32_t n)
 Decompresses a vector that was compressed using CompressNormal().
 
void ArbAxis (const Point3 &zAxis, Matrix3 &matrix)
 Creates an arbitrary axis system given an up vector that conforms to the AutoCAD algorithm.
 

Function Documentation

◆ BaryCoords() [1/2]

Point3 BaryCoords ( Point3  p0,
Point3  p1,
Point3  p2,
Point3  p 
)

Calculates the barycentric coordinates of the point p in 3-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2.

Parameters
p0,p1,p2The three vertices of the reference triangle in 3-dimensional space.
pThe point for which the barycentric coordinates should be calculated.
Returns
Barycentric coordinates of point p.
See also
BaryCoords(Point2, Point2, Point2, Point2)

◆ BaryCoords() [2/2]

Point3 BaryCoords ( Point2  p0,
Point2  p1,
Point2  p2,
Point2  p 
)

Calculates the barycentric coordinates of the point p in 2-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2.

Parameters
p0,p1,p2The three vertices of the reference triangle in 2-dimensional space.
pThe point for which the barycentric coordinates should be calculated.
Returns
Barycentric coordinates of point p.
See also
BaryCoords(Point3, Point3, Point3, Point3)

◆ RayHitsBox()

bool RayHitsBox ( Ray ray,
Box3 b 
)

Checks if the given ray intersects a three-dimensional box.

Parameters
rayThe ray
bThe box
Returns
true if the ray intersects the box, false otherwise.

◆ DistPtToLine()

float DistPtToLine ( Point2 p0,
Point2 p1,
Point2 q 
)

Calculates the distance of a given point from a line in two dimensions.

Parameters
p0,p1Pointers to the two 2-dimensional points with which the line is defined.
qPointer to the 2-dimensional point whose distance from the line should be calculated.
Returns
The distance of the point from the line.

◆ Dist3DPtToLine()

float Dist3DPtToLine ( Point3 p0,
Point3 p1,
Point3 q 
)

Calculates the distance of a given point from a line in three dimensions.

Parameters
p0,p1Pointers to the two 3-dimensional points with which the line is defined.
qPointer to the 3-dimensional point whose distance from the line should be calculated.
Returns
The distance of the point from the line.

◆ ComputeIntersectionPoint()

bool ComputeIntersectionPoint ( Point3 intersectionPoint,
geo::span< const Point3 fixedCoeffs,
geo::span< const Point3 directionVecs,
bool  doNormalize = true 
)

Compute the point of intersection, or a least squares approximation to it, for an arbitrary number N of lines in three dimensions.

The ith of the N lines is presumed to be defined in terms of the parameter s_i according to:

x = fixedCoeffs[i] + s_i * (directionVecs[i])

A least squares problem is solved for the vector s' of parameters representing (the approximations to) the point of intersection, and intersectionPoint is computed by averaging estimates from each line, as:

intersectionPoint = (1 / N) * (SUM_OVER_I(fixedCoeffs[i] + s'_i * (directionVecs[i])))
Parameters
[out]intersectionPointleast squares approximation to intersection point
[in]fixedCoeffsfixed coefficients of line representation
[in]directionVecsline direction vectors
[in]doNormalizewhen true, normalized forms of the direction vectors are used in the least squares system
Returns
Flag indicating whether solution of least squares problem was successful. If it was not, intersectionPoint will be returned as a zero vector.

◆ ComputeBumpVectors()

void ComputeBumpVectors ( const Point3  tv[3],
const Point3  v[3],
Point3  bvec[3] 
)
Deprecated:
Do not use this function. Use ComputeBumpVec2D() instead. This is here for compatibility only.

Computes the 3 bump basis vectors from the UVW coordinates of the triangle.

Parameters
tvTexture coordinates at 3 triangle vertices
vCoordinates of triangle vertices (usually in camera space).
[out]bvecThe 3 bump basis vectors (normalized) corresponding to the U,V,and W axes.

◆ ComputeBumpVec2D()

void ComputeBumpVec2D ( int  axis,
const Point3  tv[3],
const Point3  v[3],
Point3  bvec[2] 
)

Computes the 2 Bump basis vectors from the UV, VW, or WU at a triangle.

Parameters
axisEither AXIS_UV, AXIS_VW, or AXIS_WU .
tvTexture coordinates at 3 triangle vertices.
vCoordinates of triangle vertices (usually in camera space)
[out]bvecThe 2 normalized bump basis vectors corresponding to the specified axes.
Note
This is the recommended way to compute bump vectors instead of ComputeBumpVectors() which can give erroneous results.

◆ ComputeTangent()

Point3 ComputeTangent ( const Point3  tv[3],
const Point3  v[3] 
)

returns the bump basis vector for the U texture channel (called the tangent)

Parameters
tvTexture coordinates at 3 triangle vertices.
vCoordinates of triangle vertices (usually in camera space)
Returns
The 2 normalized bump basis vectors corresponding to the specified axes.

◆ ComputeTangentAndBinormal()

void ComputeTangentAndBinormal ( const Point3  tv[3],
const Point3  v[3],
Point3  bvec[2] 
)

Computes the bump basis vector for the U texture channel (called the tangent), and the cross product of the surface normal with the tangent (called the binormal).

These along with the surface normal are used as the basis vectors for normal mapping.

Parameters
tvTexture coordinates at 3 triangle vertices.
vCoordinates of triangle vertices (usually in camera space)
[out]bvecThe 2 normalized bump basis vectors corresponding to the specified axes.

◆ ComputeMikkTangents()

void ComputeMikkTangents ( ITangentsComputationCallback tangentsComputationCallback)

Computes the bump basis vector in MikkT way for the U texture channel (called the tangent), and the cross product of the surface normal with the tangent (called the binormal).

These along with the surface normal are used as the basis vectors for normal mapping.

Parameters
tangentsComputationCallbackThe callback will be called during the computation to fill all required data and receive the results of computation.

◆ ComputeUVTangents()

UVTangentVectors ComputeUVTangents ( const Point3 p0,
const Point3 p1,
const Point3 p2,
const Point2 uv0,
const Point2 uv1,
const Point2 uv2 
)

Computes the bump basis vectors for the U and V components of the texture coordinates channel (also called the tangent and bitangent).

Remarks
This function differs from ComputeTangentAndBinormal() as the latter computes the binormal - the cross product of U tangent vector and normal - rather than the V tangent (or bitangent). The binormal and bitangent will differ if the U and V coordinates are not perpendicular to each other.
Parameters
p0The XYZ coordinate of the first triangle vertex.
p1The XYZ coordinate of the second triangle vertex.
p2The XYZ coordinate of the third triangle vertex.
uv0The UV coordinate of the first triangle vertex.
uv1The UV coordinate of the second triangle vertex.
uv2The UV coordinate of the third triangle vertex.
Returns
Two unit vectors in XYZ space, tangent to the surface of the given triangle, aligned with the U and V directions of the given texture coordinates.

◆ CompressNormal()

uint32_t CompressNormal ( Point3  p)

Low precision compression of a vector from 12 bytes to 4 bytes.

Only accurate to 1 part in 512. This is commonly used to compress normals. The vector has to be <= 1.0 in length.

Parameters
pThe decompressed vector.
Returns
The 4-byte long compressed value of p
See also
DeCompressNormal(), BMM_CHAN_NORMAL

◆ DeCompressNormal()

Point3 DeCompressNormal ( uint32_t  n)

Decompresses a vector that was compressed using CompressNormal().

This function may also be used to decompress a surface normal from the G-Buffer using the BMM_CHAN_NORMAL channel. The decompressed vector has absolute error <.001 in each component.

Parameters
nA vector compressed using CompressNormal()
Returns
A normalized decompressed normal vector
See also
CompressNormal()

◆ ArbAxis()

void ArbAxis ( const Point3 zAxis,
Matrix3 matrix 
)

Creates an arbitrary axis system given an up vector that conforms to the AutoCAD algorithm.

Parameters
zAxisThe up vector.
[out]matrixThe new axis system.