3ds Max C++ API Reference
IParameterTranslator Class Referenceabstract

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

#include <IParameterTranslator.h>

+ Inheritance diagram for IParameterTranslator:

Public Types

enum  ShaderParameterType {
  ShaderParameterTypeUnknown = 0 , ShaderParameterTypeFloat , ShaderParameterTypeInt , ShaderParameterTypeBool ,
  ShaderParameterTypeColor , ShaderParameterTypePoint2 , ShaderParameterTypePoint3 , ShaderParameterTypePoint4 ,
  ShaderParameterTypeTexture , ShaderParameterTypeMatrix4
}
 Shader parameter types. More...
 
enum  SubMtlBaseType { SubMaterial , SubTexmap }
 The type of plug-in's "sub" slot. More...
 
- Public Types inherited from BaseInterface
enum  LifetimeType { noRelease , immediateRelease , wantsRelease , serverControlled }
 

Public Member Functions

virtual Interface_ID GetID ()
 Retrieves the interface id of IParameterTranslator. More...
 
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. More...
 
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. More...
 
virtual bool OnPreParameterTranslate ()=0
 One time setup before any parameter is translated. More...
 
- Public Member Functions inherited from BaseInterface
virtual UtilExport ~BaseInterface ()
 Destructor. More...
 
UtilExport BaseInterfaceGetInterface (Interface_ID id)
 
virtual LifetimeType LifetimeControl ()
 
virtual bool RegisterNotifyCallback (InterfaceNotifyCallback *incb)
 
virtual void UnRegisterNotifyCallback (InterfaceNotifyCallback *incb)
 
virtual BaseInterfaceAcquireInterface ()
 
virtual void ReleaseInterface ()
 
virtual void DeleteInterface ()
 
virtual BaseInterfaceCloneInterface (void *remapDir=NULL)
 
- Public Member Functions inherited from InterfaceServer
virtual UtilExport ~InterfaceServer ()
 Destructor. More...
 
template<class InterfaceType >
InterfaceType * GetTypedInterface ()
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

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,
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;
}
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;
};
}
Facilitates translation of material and texture map parameter values to their shaders representation.
Definition: IParameterTranslator.h:83
SubMtlBaseType
The type of plug-in's "sub" slot.
Definition: IParameterTranslator.h:102
@ SubTexmap
sub texmap type
Definition: IParameterTranslator.h:104
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.
ShaderParameterType
Shader parameter types.
Definition: IParameterTranslator.h:87
@ ShaderParameterTypeInt
int type
Definition: IParameterTranslator.h:90
@ ShaderParameterTypeFloat
float type
Definition: IParameterTranslator.h:89
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 OnPreParameterTranslate()=0
One time setup before any parameter is translated.
Definition: MtlBase.h:159
Definition: strclass.h:738
#define DbgAssert(expr)
Definition: assert1.h:82
int TimeValue
Definition: maxtypes.h:118
#define _M(x)
Used to wrap string literals.
Definition: strbasic.h:67
#define MCHAR
MBCS/Unicode helper defines std::wofstream doesn't mix well with Unicode.
Definition: strbasic.h:42

Member Enumeration Documentation

◆ ShaderParameterType

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.

ShaderParameterTypeMatrix4 

matrix44 type

87  {
98  };
@ ShaderParameterTypeUnknown
unknown parameter type
Definition: IParameterTranslator.h:88
@ ShaderParameterTypePoint4
Point4 type.
Definition: IParameterTranslator.h:95
@ ShaderParameterTypeTexture
MSTR type.
Definition: IParameterTranslator.h:96
@ ShaderParameterTypePoint2
Point2 type.
Definition: IParameterTranslator.h:93
@ ShaderParameterTypeBool
BOOL type.
Definition: IParameterTranslator.h:91
@ ShaderParameterTypeMatrix4
matrix44 type
Definition: IParameterTranslator.h:97
@ ShaderParameterTypeColor
AColor type.
Definition: IParameterTranslator.h:92
@ ShaderParameterTypePoint3
Point3 type.
Definition: IParameterTranslator.h:94

◆ SubMtlBaseType

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

Enumerator
SubMaterial 

sub material type

SubTexmap 

sub texmap type

102  {
103  SubMaterial,
104  SubTexmap,
105  };
@ SubMaterial
sub material type
Definition: IParameterTranslator.h:103

Member Function Documentation

◆ GetID()

virtual Interface_ID GetID ( )
inlinevirtual

Retrieves the interface id of IParameterTranslator.

Reimplemented from BaseInterface.

#define IPARAMETER_TRANSLATOR_INTERFACE_ID
Interface ID of class IParameterTranslator.
Definition: IParameterTranslator.h:16

◆ GetParameterValue()

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]tThe time at which to retrieve the plug-in's parameter value
[in]shaderParamNameThe name of the shader parameter. The name is not case sensitive.
[out]valuePointer 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]typeThe type of the shader parameter
Returns
Returns true if the plug-in parameter value was retrieved successfully, false otherwise.

◆ GetShaderInputParameterName()

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]typeThe type of plug-in's "sub" slot
[in]subMtlBaseIndexThe index of the "sub" slot within the plug-ins list of slots
[out]shaderInputParamNameThe shader input parameter name
Returns
true if the shader name was successfully generated, false otherwise.

◆ OnPreParameterTranslate()

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.