Class XYZGen

3DS Max Plug-In SDK

Class XYZGen

See Also: Class MtlBase, Class ShadeContext, Class Point3.

class XYZGen : public MtlBase

Description:

This class generates Point3 coordinates based on the ShadeContext. A reference to one of these is referenced by all 3D texture maps. XYZGen does for 3D Texmaps what UVGen does for 2D Texmaps. It puts up the 3D "Coordinates" rollup, and supplies the 3D Texmap with transformed 3D coordinates. All methods of this class are implemented by the system.

Methods:

Prototype:

virtual void GetXYZ(ShadeContext& sc, Point3& p, Point3& dp)=0;

Remarks:

This method retrieves coordinates and derivatives for antialiasing. It returns the coordinates in the "Object Coordinate System", scaled and rotated by the parameters given in the Coordinates rollup. The default transformation is the identity transform, so you just get Object coordinates. For instance, if you have a sphere of radius 100, you will get coordinates ranging from -100 to +100.

A developer might wonder why 3ds max don't use some normalized coordinates space. This was considered, but it has some real problems. Say you make something by assembling several boxes, of varying sizes, and then apply a wood texture to the whole thing. You want the wood texture to be at the same scale for all the pieces, not smaller on the smaller pieces, and thus that doesn't work.

Parameters:

ShadeContext& sc

Describes the properties of the point to be shaded.

Point3& p

The 3D point is returned here.

Point3& dp

The derivative of the 3D point is returned here.

Prototype:

virtual BOOL IsStdUVGen();

Remarks:

This method is available in release 2.0 and later only.

This method asks the question 'Is this class an instance of StdUVGen?'. The derived class StdUVGen implements this to return TRUE. Others use the default implementation to return FALSE.

Default Implementation:

{ return FALSE; }

Prototype:

virtual void SetRollupOpen(BOOL open)=0;

Remarks:

This method is available in release 3.0 and later only.

Sets the XYZGen rollup state to open or closed.

Parameters:

BOOL open

TRUE for open; FALSE for closed.

Prototype:

virtual BOOL GetRollupOpen()=0;

Remarks:

This method is available in release 3.0 and later only.

Returns the open or closed state of the XYZGen rollup.

Return Value:

TRUE is open; FALSE is closed.

Prototype:

virtual void GetBumpDP(ShadeContext& sc, Point3* dP);

Remarks:

This method is available in release 3.0 and later only.

This method returns the transformed bump unit vectors for 3D bump mapping. The 3D textures need to use these in computing the gradient.

Parameters:

ShadeContext& sc

Describes the properties of the point to be shaded.

Point3* dP

The 3 unit vectors for computing differentials are returned here.

Default Implementation:

{}

Sample Code:

Here is a typical use of XYZGen->GetBumpDP() to compute the bump mapping for a 3D texture:

Point3 Marble::EvalNormalPerturb(ShadeContext& sc) {

 float del,d;

 Point3 p,dp;

 if (!sc.doMaps) return Point3(0,0,0);

 if (gbufID) sc.SetGBufferID(gbufID);

 xyzGen->GetXYZ(sc,p,dp);

 if (size==0.0f) size=.0001f;

 p *= FACT/size;

 d = MarbleFunc(p);

 del = 20.0f;

 Point3 np;

 Point3 M[3];

 xyzGen->GetBumpDP(sc,M);

 np.x = (MarbleFunc(p+del*M[0]) - d)/del;

 np.y = (MarbleFunc(p+del*M[1]) - d)/del;

 np.z = (MarbleFunc(p+del*M[2]) - d)/del;

 np *= 100.0f;

 return sc.VectorFrom(np,REF_OBJECT);

 }