Class RenderInstance

3DS Max Plug-In SDK

Class RenderInstance

See Also: Class Mtl, Class LightDesc, Class INode, Class Object, Class Mesh, Class Matrix3, Class Box3, Class Point3, Class Interval.

class RenderInstance

Description:

This class is available in release 2.0 and later only.

This class provides information about a single node being rendered. This includes information such as the mesh of the object, its material, unique node ID, object space bounding extents, number of lights affecting it, material requirements, and normals and vertex coordinates in various spaces (object and camera).

Data Members:

public:

ULONG flags;

The flags that describe the properties of this instance. See List of Render Instance Flags.

Mtl *mtl;

This is the material from the node.

float wireSize;

The wireframe size.

Mesh *mesh;

The mesh to be rendered. This is the result of GeomObject::GetRenderMesh().

float vis;

Object visibility (between 0.0 and 1.0). This is the value the visibility track evaluates to at a particular time.

int nodeID;

A unique ID associated with the node. It's unique within the scene during a render.

int objMotBlurFrame;

This will be equal to NO_MOTBLUR for all non-blurred objects. For blurred objects, it takes on the values (0..nBlurFrames-1) for the successive blur-instances.

int objBlurID;

The purpose of this is to differentiate blur-instances generated from different nodes. All the blur-instances for an object-motion-blurred object will have the same objBlurID. This is as distinct from nodeID, which is different for every instance. This makes it possible to easily avoid intersecting a ray with all blur-instances for an object. If RenderGlobalContext::IntersectWorld() is being used, then passing in the objBlurID for the parameter skipID will have this effect.

The basic technique is this: When reflecting or refracting rays, and object motion blur is enabled, choose sub-frame times randomly for the different rays (effectively giving a coarse stochastic sampling of time).

Matrix3 objToWorld;

This matrix can be used to transform object coordinates to world coordinates.

Matrix3 objToCam;

This matrix can be used to transform object coordinates to camera coordinates.

Matrix3 normalObjToCam;

This matrix can be used for transforming surface normals from object space to camera space.

Matrix3 camToObj;

This matrix can be used to transform camera coordinates to object coordinates.

Box3 obBox;

The object space extents of the object being rendered.

Point3 center;

The object bounding sphere center (in camera coordinates)

float radsq;

The square of the bounding sphere's radius.

Methods:

Prototype:

void SetFlag(ULONG f, BOOL b);

Remarks:

Sets the specified flag(s) to the state passed.

Parameters:

ULONG f

The flags to set. See List of Render Instance Flags.

BOOL b

The state to set; TRUE for on; FALSE for off.

Prototype:

void SetFlag(ULONG f);

Remarks:

Sets the specified flag(s) to on.

Parameters:

ULONG f

The flags to set. See List of Render Instance Flags.

Prototype:

void ClearFlag(ULONG f);

Remarks:

Clears the specified flag(s).

Parameters:

ULONG f

The flags to set to zero. See List of Render Instance Flags.

Prototype:

BOOL TestFlag(ULONG f);

Remarks:

Returns TRUE if the specified flag(s) are set; otherwise FALSE.

Parameters:

ULONG f

The flags to set to zero. See List of Render Instance Flags.

Prototype:

virtual RenderInstance *Next()=0;

Remarks:

Returns a pointer to the next in RenderInstance in the list. A pointer to the first element in the list may to retrieved from RenderGlobalContext::InstanceList().

Prototype:

virtual Interval MeshValidity()=0;

Remarks:

Returns the validity interval of the mesh of this render instance.

Prototype:

virtual int NumLights()=0;

Remarks:

Returns the number of lights affecting the node.

Prototype:

virtual LightDesc *Light(int n)=0;

Remarks:

Returns a pointer to the LightDesc for the 'i-th' light affecting the node.

Parameters:

int n

Specifies which light.

Prototype:

virtual BOOL CastsShadowsFrom(const ObjLightDesc& lt)=0;

Remarks:

This method is available in release 3.0 and later only.

Returns TRUE if this particular instance will cast shadows from the particular light based on the light’s Exclusion/Inclusion list; FALSE if it won't cast shadows.

Parameters:

const ObjLightDesc& lt

Describes the light. See Class ObjLightDesc.

Prototype:

virtual INode *GetINode()=0;

Remarks:

Returns the INode pointer for the instance.

Prototype:

virtual Object *GetEvalObject()=0;

Remarks:

Returns a pointer to the evaluated object for the instance. You can use this to get more information about the type of object being rendered. For instance you could look at the Class_ID and recognize it as a sphere, a box, a torus, etc.

Prototype:

virtual ULONG MtlRequirements(int mtlNum, int faceNum)=0;

Remarks:

Returns the material requirements of the material assigned to the node. See List of Material Requirement Flags.

Parameters:

int mtlNum

Specifies the number of the sub-material whose requirements should be returned. A value of -1 may be passed to return a value generated by looping over all the sub-materials and ORing together the requirements.

int faceNum

This parameter is available in release 4.0 and later only.

This is the integer face number for objects which support material per face (if flag INST_MTL_BYFACE is set). See Class IChkMtlAPI.

Prototype:

virtual Point3 GetFaceNormal(int faceNum)=0;

Remarks:

Returns the geometric normal of the specified face in object space.

Parameters:

int faceNum

Zero based index of the face whose normal is returned.

Prototype:

virtual Point3 GetFaceVertNormal(int faceNum, int vertNum)=0;

Remarks:

Returns the vertex normal of the specified face in camera coordinates.

Parameters:

int faceNum

Zero based index of the face in the mesh.

int vertNum

Zero based index of the vertex in the face.

Prototype:

virtual void GetFaceVertNormals(int faceNum, Point3 n[3])=0;

Remarks:

Returns the three vertex normals of the specified face in camera coordinates.

Parameters:

int faceNum

Zero based index of the face in the mesh.

Point3 n[3]

The normals are returned here.

Prototype:

virtual Point3 GetCamVert(int vertnum)=0;

Remarks:

Returns the coordinate for the specified vertex in camera coordinates

Parameters:

int vertnum

The zero based index of the vertex in the mesh.

Prototype:

virtual void GetObjVerts(int fnum, Point3 obp[3])=0;

Remarks:

Returns the vertices of the specified face in object coordinates.

Parameters:

int fnum

Zero based index of the face in the mesh.

Point3 obp[3]

The three vertices of the face in object coordinates.

Prototype:

virtual void GetCamVerts(int fnum, Point3 cp[3])=0;

Remarks:

Returns the vertices of the specified face in camera (view) coordinates.

Parameters:

int fnum

Zero based index of the face in the mesh.

Point3 cp[3]

The three vertices of the face in camera coordinates.

Prototype:

virtual Mtl *GetMtl(int faceNum)=0;

Remarks:

This method is available in release 4.0 and later only.

Objects can provide a material as a function of face number via the interface provided by Class IChkMtlAPI. This method will return RenderInstance::mtl if flag INST_MTL_BYFACE is not set. If INST_MTL_BYFACE is set it will return the proper by-face material. See List of Render Instance Flags.

Parameters:

int faceNum

The zero based index of the face in the mesh.

Objects can provide a material as a function of face number via the IChkMtlAPI interface (chkmtlapi.h).

Prototype:

virtual INT_PTR Execute(int cmd, ULONG arg1=0, ULONG arg2=0, ULONG arg3=0)=0;

Remarks:

This method is available in release 2.0 and later only.

This is a general purpose function that allows the API to be extended in the future. The 3ds max development team can assign new cmd numbers and continue to add functionality to this class without having to 'break' the API.

Parameters:

int cmd

The index of the command to execute.

ULONG arg1=0

Optional argument 1. See the documentation where the cmd option is discussed for more details on these parameters.

ULONG arg2=0

Optional argument 2.

ULONG arg3=0

Optional argument 3.

Return Value:

An integer return value. See the documentation where the cmd option is discussed for more details on the meaning of this value.

Default Implementation:

{ return 0; }