Public Member Functions

UVGen Class Reference

This reference page is linked to from the following overview topics: Principal Classes for Materials and Textures, Editing Material and Texture Parameters, Function and Macros for Use with Materials, Bump Mapping.


Search for all occurrences

Detailed Description

See also:
Class MtlBase, Class ShadeContext, Class MapSampler, Class Point2, Class Point3, Class Matrix3.

Description:
Most texture maps that use UV coordinates will use an instance of this class. This class encapsulates much of the user interface functionality for setting mirroring, tiling and so on. These are the settings found in the 'Coordinate' and 'Noise' rollup pages. This class generates UV coordinates based on the results of a UV source provided by the plug-in and the user specified transformations. An instance of this class is referenced by all the 2D texture maps. All methods of this class are implemented by the system.
The following four methods are the only ones a plug-in needs to call typically:

#include <imtl.h>

Inheritance diagram for UVGen:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual void  GetUV (ShadeContext &sc, Point2 &UV, Point2 &dUV)=0
virtual AColor  EvalUVMap (ShadeContext &sc, MapSampler *samp, BOOL filter=TRUE)=0
virtual float  EvalUVMapMono (ShadeContext &sc, MapSampler *samp, BOOL filter=TRUE)=0
virtual Point2  EvalDeriv (ShadeContext &sc, MapSampler *samp, BOOL filter=TRUE)=0
virtual void  GetBumpDP (ShadeContext &sc, Point3 &dPdu, Point3 &dPdv)=0
virtual void  GetUVTransform (Matrix3 &uvtrans)=0
virtual int  GetTextureTiling ()=0
virtual void  SetTextureTiling (int t)=0
virtual int  GetUVWSource ()=0
virtual int  GetMapChannel ()
virtual void  SetUVWSource (int s)=0
virtual void  SetMapChannel (int s)
virtual int  SymFlags ()=0
virtual void  SetSymFlags (int f)=0
virtual int  GetSlotType ()=0
virtual void  InitSlotType (int sType)=0
virtual int  GetAxis ()=0
virtual void  SetAxis (int ax)=0
virtual void  SetClipFlag (BOOL b)=0
virtual BOOL  GetClipFlag ()=0
virtual BOOL  IsStdUVGen ()
SClass_ID  SuperClassID ()
  Retrieves a constant representing the type of the plugin.
virtual void  SetRollupOpen (BOOL open)=0
virtual BOOL  GetRollupOpen ()=0
CoreExport SvGraphNodeReference  SvTraverseAnimGraph (IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags)
CoreExport MSTR  SvGetName (IGraphObjectManager *gom, IGraphNode *gNode, bool isBeingEdited)

Member Function Documentation

virtual void GetUV ( ShadeContext sc,
Point2 UV,
Point2 dUV 
) [pure virtual]
Remarks:
This method is not normally called directly. It retrieves the UV coordinates (depending on if they are explicit, shrinked-wrapped environment, etc.) and transforms them using the offsets and noise parameters entered by the user. It does not do the mirroring or tiling. It then returns the texture coordinates and derivatives for antialiasing.
Parameters:
ShadeContext& sc

Describes the properties of the point to evaluate.

Point2& UV

The UV texture coordinates for the point.

Point2& dUV

The derivatives of UV for the point to shade. This describes how big of a range in UV space the current pixel covers.
virtual AColor EvalUVMap ( ShadeContext sc,
MapSampler samp,
BOOL  filter = TRUE 
) [pure virtual]
Remarks:
This method is called to evaluate the color of the map based on the ShadeContext. It takes into account the users selections for mirroring, tiling, noise, etc. from the UVGen rollups.
Parameters:
ShadeContext &sc

Describes the properties of the point to evaluate.

MapSampler* samp

This is a callback used to sample the map. The plug-in creates an instance of this class, and implements its methods. A pointer to the instance is passed here. The methods of the class sample the texture for a single UV coordinate.

BOOL filter=TRUE

If TRUE the texture will be filtered.
Returns:
The result as an AColor.
virtual float EvalUVMapMono ( ShadeContext sc,
MapSampler samp,
BOOL  filter = TRUE 
) [pure virtual]
Remarks:
This method is called to evaluate the value of the map based on the ShadeContext. It takes into account the users selections for mirroring, tiling, noise, etc. from the UVGen rollups.
Parameters:
ShadeContext &sc

Describes the properties of the point to evaluate.

MapSampler* samp

This is a callback used to sample the map. The plug-in creates an instance of this class, and implements its methods. A pointer to the instance is passed here. The methods of the class sample the texture for a single UV coordinate.

BOOL filter=TRUE

If TRUE the texture will be filtered.
Returns:
The result as a float.

The following two methods are called for bump mapping to retrieve a normal perturbation. The calling sequence for these methods is shown in the sample code below. This code takes the sum of the U derivative times the U bump vector, and the V derivative times the V bump vector. The result is the normal perturbation returned from EvalNormalPerturb().
            Point3 BMTex::EvalNormalPerturb(ShadeContext& sc)
            {
                Point3 dPdu, dPdv;
                if (thebm==NULL)
                    return Point3(0,0,0);
                uvGen->GetBumpDP(sc,dPdu,dPdv);               // get bump basis vectors
                Point2 dM =(.01f)*uvGen->EvalDeriv(sc,&mysamp,filterType!=FILTER_NADA);
                return texout->Filter(dM.x*dPdu+dM.y*dPdv);
            }
Note: In the following code you'll see the 'text book' Blinn's algorithm and the 'Lazy' approach that is actually used. During testing it was determined that these two methods are visually identical. The 'Lazy' algorithm avoids the cross products however.
            Point3 Gradient::EvalNormalPerturb(ShadeContext\& sc) {
                Point3 dPdu, dPdv;
                Point2 dM = uvGen->EvalDeriv(sc,\&mysamp);
                uvGen->GetBumpDP(sc,dPdu,dPdv);
                // Lazy algorithm
                return texout->Filter(dM.x*dPdu+dM.y*dPdv);
            } 
virtual Point2 EvalDeriv ( ShadeContext sc,
MapSampler samp,
BOOL  filter = TRUE 
) [pure virtual]
Remarks:
This gets the amount that U and V are changing. It takes into account the users selections for mirroring, tiling, noise, etc. from the UVGen rollups.
Parameters:
ShadeContext& sc

Describes the properties of the point to evaluate.

MapSampler* samp

This is a callback used to sample the map. The plug-in creates an instance of this class, and implements its methods. A pointer to the instance is passed here. The methods of the class sample the texture for a single UV coordinate.

BOOL filter=TRUE

If TRUE the texture will be filtered.
Returns:
df/du, df/dv as a Point2.
virtual void GetBumpDP ( ShadeContext sc,
Point3 dPdu,
Point3 dPdv 
) [pure virtual]
Remarks:
This method may be called to compute dPdu and dPdv bump basis vectors for bump mapping. These are two vector in 3D space that give you the U and V axis of the map space. This is like taking the map space into 3D space so you can determine where the U axis is and where the V axis is.

Note: In 3ds Max 3.0 and later these vectors are always normalized. This change makes it so bump mapping is invariant when a Rescale World Units is performed.

See the Advanced Topics section on Working with Materials and Textures for more information on bump mapping.
Parameters:
ShadeContext& sc

Describes the properties of the point to evaluate.

Point3& dPdu, Point3& dPdv

The bump basis vectors are returned here.
virtual void GetUVTransform ( Matrix3 uvtrans ) [pure virtual]
Remarks:
This method is used internally to provide information to the interactive renderer.
virtual int GetTextureTiling ( ) [pure virtual]
Remarks:
This method is used internally to provide information to the interactive renderer.

Implemented in StdUVGen.

virtual void SetTextureTiling ( int  t ) [pure virtual]
virtual int GetUVWSource ( ) [pure virtual]
Remarks:
This method returns the source for the texture vertices.
Returns:
One of the following values:

UVWSRC_EXPLICIT

Use explicit mesh texture vertices from channel 1.

UVWSRC_EXPLICIT2

Use explicit mesh texture vertices from channel 2.

UVWSRC_OBJXYZ

Generate planar UVW mapping coordinates from the object XYZ on-the-fly.
virtual int GetMapChannel ( ) [inline, virtual]

Reimplemented in StdUVGen.

{ return 1; }   // only relevant if above returns UVWSRC_EXPLICIT
virtual void SetUVWSource ( int  s ) [pure virtual]
Remarks:
This method sets the source for the texture vertices.
Parameters:
int s

One of the following values:

UVWSRC_EXPLICIT

Use explicit mesh texture vertices from one of the mapping channels (as established by SetMapChannel() below).

UVWSRC_EXPLICIT2

Use explicit mesh texture vertices from the Vertex Color Channel.

UVWSRC_OBJXYZ

Generate planar UVW mapping coordinates from the object XYZ on-the-fly.

UVWSRC_WORLDXYZ

This parameter is available in release 3.0 and later only.

Generate planar uvw mapping from world xyz on-the-fly.
virtual void SetMapChannel ( int  s ) [inline, virtual]
Remarks:
Sets the mapping channel used when UVWSRC_EXPLICIT is in effect.
Parameters:
int s

The mapping channel value to set.
Default Implementation:
{}

Reimplemented in StdUVGen.

{ }
virtual int SymFlags ( ) [pure virtual]
Remarks:
This method is used internally.
virtual void SetSymFlags ( int  f ) [pure virtual]
Remarks:
This method is used internally.
virtual int GetSlotType ( ) [pure virtual]
virtual void InitSlotType ( int  sType ) [pure virtual]
Remarks:
Developers typically don't need to call this method. In the Coordinates rollup in the user interface for a texture map are two options. These options are Texture or Environment. The slot type is one of these two options. There are a variety of texture coordinate types. There are the type assigned to the object and the environment type (Spherical, Cylindrical, Shrink-wrap, Screen). This method is used initialize the radio button in the dialog based on the sType passed and update the drop down list.
Parameters:
int sType

One of the following values:

MAPSLOT_TEXTURE

This is either texture coordinates.

MAPSLOT_ENVIRON

Environment coordinates.
virtual int GetAxis ( ) [pure virtual]
Remarks:
Return the axis (mapping coordinate system) used.
Returns:
One of the following values:

AXIS_UV

AXIS_VW

AXIS_WU
virtual void SetAxis ( int  ax ) [pure virtual]
Remarks:
Sets the axis (mapping coordinate system) used.
Parameters:
int ax

One of the following values:

AXIS_UV

AXIS_VW

AXIS_WU
virtual void SetClipFlag ( BOOL  b ) [pure virtual]
Remarks:
This method sets the clip flag. The clip flag controls whether the U,V values passed to MapSampler by EvalUVMap() and EvalUVMapMono() are clipped to the [0..1] interval or not. It defaults to ON (i.e., clipped).

If an object is covered by a texture, and that texture repeats (is tiled), this methods can be used to tell you which tile you're in. This allows one to do something depending on which tile it is. This is done, for example, in the Bitmap texture, when 'Jitter Placement' is on, so each tile can be moved about slightly. For an example of this see /MAXSDK/SAMPLES/MATERIALS/BMTEX.CPP. If you need this information, you can just call uvGen->SetClipFlag(FALSE) (for instance in your Update() method) and then use int(u) and int(v) to get the this info. (You'd use frac(u) and frac(v) to get clipped versions of u,v. )
Parameters:
BOOL b

TRUE to clip; FALSE to not clip.
virtual BOOL GetClipFlag ( ) [pure virtual]
Remarks:
This method returns the clip flag. The clip flag controls whether the U,V values passed to MapSampler by EvalUVMap() and EvalUVMapMono() are clipped to the [0..1] interval or not. It defaults to ON (i.e., clipped). See SetClipFlag() above.
Returns:
TRUE for clipped; FALSE if not clipped.
virtual BOOL IsStdUVGen ( ) [inline, virtual]
Remarks:
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; }

Reimplemented in StdUVGen.

{ return FALSE; } // class StdUVGen implements this to return TRUE
SClass_ID SuperClassID ( ) [inline, virtual]

Retrieves a constant representing the type of the plugin.

Returns:
A super class id that uniquely identifies the type (category) of the plugin. Note that several plugin classes can be of the same type, thus return the same super class id. Plugins are uniquely identified by their class ids. List of Super Class IDs.
See also:
SClass_ID

Reimplemented from ReferenceTarget.

{ return UVGEN_CLASS_ID; }
virtual void SetRollupOpen ( BOOL  open ) [pure virtual]
Remarks:
Sets the UVGen rollup state to open or closed.
Parameters:
BOOL open

TRUE for open; FALSE for closed.
virtual BOOL GetRollupOpen ( ) [pure virtual]
Remarks:
Returns the open or closed state of the UVGen rollup.
Returns:
TRUE is open; FALSE is closed.
CoreExport SvGraphNodeReference SvTraverseAnimGraph ( IGraphObjectManager gom,
Animatable owner,
int  id,
DWORD  flags 
) [virtual]
Remarks:
This method is available in release 3.0 and later only.

This method traverses the graph of objects in the 3ds Max scene, adding desired objects to the schematic view. Developers can specialize this behaviour by overriding this method and adding whatever objects are interesting to the schematic view. Objects are added to the schematic view by calling IGraphObjectManager::AddAnimatable(...). Reference lines are added to the schematic view by calling IGraphObjectManager::AddReference(...). Implementers of this method should call it recursively to process other objects in the scene.

See Class IGraphObjectManager.
Parameters:
gom Points to the schematic view window manager.
owner The owning animatable.
id This is usually the sub-anim number (but can actually be any value the developer chooses).
flags See List of Schematic %View AddAnimatable Flags.
Returns:
A SvGraphNodeReference object.

Reimplemented from MtlBase.

CoreExport MSTR SvGetName ( IGraphObjectManager gom,
IGraphNode gNode,
bool  isBeingEdited 
) [inline, virtual]
Remarks:
Returns the name of the object as it appears in the schematic view.
Parameters:
gom Points to the schematic view window manager.
gNode Points to this node in the schematic view.
isBeingEdited TRUE if the item is being edited; FALSE if not.
Default Implementation:
        {
            Animatable *owner;
            int subNum;
            MSTR name;
            owner = gNode->GetOwner();
            subNum = gNode->GetID();
            name = owner->SubAnimName(subNum);
            return name;
        }

Reimplemented from MtlBase.

                 {
                 return Animatable::SvGetName(gom, gNode, isBeingEdited);
                 }

UVGen UVGen UVGen UVGen UVGen UVGen UVGen UVGen UVGen UVGen
UVGen UVGen UVGen UVGen UVGen UVGen UVGen UVGen UVGen UVGen