IParameterTranslator Class Reference

This reference page is linked to from the following overview topics: Porting Advanced Material and Texture Map Plug-ins to Nitrous.



Detailed Description

Facilitates translation of material and texture map parameter values to their shaders representation.

Materials and texture maps can use programmable shaders to describe their appearance when displayed in the Nitrous viewport and rendered with Quicksilver. Programmable shaders allow for a more realistic and complex visual appearance than ISimpleMaterial does. Note that 3ds Max 2012 only supports MetaSL shaders. See IShaderManager for more details.

The Nitrous graphics system handles automatic translation of Paramblock2 based material and texture map parameters given that their names and types match those of the shader. IParameterTranslator allows plug-ins to control this translation process. Nitrous queries the plug-in for the IParameterTranslator interface by passing IPARAMETER_TRANSLATOR_INTERFACE_ID to its overwrite of Animatable::GetInterface(Interface_ID), and uses it instead of its own automated translation. Nitrous automatically detects when a plug-in's parameters, reference structure or animatable structure changes, and will call the methods on this interface to re-translate the plug-in's parameters to the shader.

The following code snippet illustrates how a material plug-in may implement IParameterTranslator:

    #include <.\graphics\IParameterTranslator.h>
    // A material plug-in that has a shader and needs to control the parameter translation process
    class MyMtlPlugin : public MtlBase, public MaxSDK::Graphics::IParameterTranslator {
        // Parameter block definition omitted for brevity
    public:
        virtual bool GetParameterValue(
        const TimeValue t, 
        const MCHAR* shaderParamName, 
        void* value, 
        MaxSDK::Graphics::IParameterTranslator::ShaderParameterType shaderParamType) {
            if (_tcscmp(_M("myFloatShaderParam"), shaderParamName) == 0) {
                DbgAssert(ShaderParameterTypeFloat == shaderParamType);
                float floatParam = // Get float parameter value from parameter block
                *(float*)value = floatParam;
                return true;
            }
            else if (_tcscmp(_M("myIntShaderParam"), shaderParamName) == 0) {
                DbgAssert(ShaderParameterTypeInt == shaderParamType);
                *(int*)value = 1; // the value of this parameter is constant
                return true;
            }
            // etc
            DbgAssert(false && _M("Unexpected shader parameter"));
            return false;
        }
        virtual bool GetShaderInputParameterName(
            MaxSDK::Graphics::IParameterTranslator::SubMtlBaseType shaderType, 
            int subMtlBaseIndex, 
            MSTR& shaderParamName) {
                if (shaderType == SubTexmap && 1 == subMtlBaseIndex) {
                    shaderParamName = // name of input shader parameter corresponding to sub texture map slot 1
                    return true;
                }
                return false;
            }
        virtual bool OnPreParameterTranslate() { 
            // Nothing to pre-process or initialize 
            return true; 
        };
    }

#include <IParameterTranslator.h>

Inheritance diagram for IParameterTranslator:
Inheritance graph
[legend]

List of all members.

Public Types

enum   ShaderParameterType {
  ShaderParameterTypeUnknown = 0, ShaderParameterTypeFloat, ShaderParameterTypeInt, ShaderParameterTypeBool,
  ShaderParameterTypeColor, ShaderParameterTypePoint2, ShaderParameterTypePoint3, ShaderParameterTypePoint4,
  ShaderParameterTypeTexture
}
 

Shader parameter types.

More...
enum   SubMtlBaseType { SubMaterial, SubTexmap }
 

The type of plug-in's "sub" slot.

More...

Public Member Functions

virtual Interface_ID  GetID ()
  Retrieves the interface id of IParameterTranslator.
virtual bool  GetParameterValue (const TimeValue t, const MCHAR *shaderParamName, void *value, ShaderParameterType type)=0
  Retrieves the plug-in's parameter value that corresponds to a given shader parameter.
virtual bool  GetShaderInputParameterName (SubMtlBaseType type, int subMtlBaseIndex, MSTR &shaderInputParamName)=0
  Retrieves the shader input parameter name for a given "sub" slot of the plug-in.
virtual bool  OnPreParameterTranslate ()=0
  One time setup before any parameter is translated.

Member Enumeration Documentation

Shader parameter types.

Enumerator:
ShaderParameterTypeUnknown 

unknown parameter type

ShaderParameterTypeFloat 

float type

ShaderParameterTypeInt 

int type

ShaderParameterTypeBool 

BOOL type.

ShaderParameterTypeColor 

AColor type.

ShaderParameterTypePoint2 

Point2 type.

ShaderParameterTypePoint3 

Point3 type.

ShaderParameterTypePoint4 

Point4 type.

ShaderParameterTypeTexture 

MSTR type.

The type of plug-in's "sub" slot.

Enumerator:
SubMaterial 

sub material type

SubTexmap 

sub texmap type


Member Function Documentation

virtual Interface_ID GetID ( ) [inline, virtual]

Retrieves the interface id of IParameterTranslator.

Reimplemented from BaseInterface.

{ return IPARAMETER_TRANSLATOR_INTERFACE_ID; }
virtual bool GetParameterValue ( const TimeValue  t,
const MCHAR *  shaderParamName,
void *  value,
ShaderParameterType  type 
) [pure virtual]

Retrieves the plug-in's parameter value that corresponds to a given shader parameter.

Parameters:
[in] t The time at which to retrieve the plug-in's parameter value
[in] shaderParamName The name of the shader parameter. The name is not case sensitive.
[out] value Pointer to a data structure that will store the plug-in's parameter value. This parameter will need to be cast to one of the supported types - see ShaderParameterType
[in] type The type of the shader parameter
Returns:
Returns true if the plug-in parameter value was retrieved successfully, false otherwise.
virtual bool GetShaderInputParameterName ( SubMtlBaseType  type,
int  subMtlBaseIndex,
MSTR shaderInputParamName 
) [pure virtual]

Retrieves the shader input parameter name for a given "sub" slot of the plug-in.

The plug-in need to "compute" the name of the input shader parameter that corresponds to a given "sub" slot identified by its slot index and type. Nitrous will connect the shader corresponding to material or texture map at that "sub" slot with the shader input parameter that has the name this method generates.

Parameters:
[in] type The type of plug-in's "sub" slot
[in] subMtlBaseIndex The index of the "sub" slot within the plug-ins list of slots
[out] shaderInputParamName The shader input parameter name
Returns:
true if the shader name was successfully generated, false otherwise.
virtual bool OnPreParameterTranslate ( ) [pure virtual]

One time setup before any parameter is translated.

Called once before the parameter list is parsed. This could be used to make sure all parameters are valid before being translated.

Returns:
If it returns false, the translation does not take place.

IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator
IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator IParameterTranslator