Public Member Functions | Protected Member Functions | Protected Attributes

MtlBaseLib Class Reference

This reference page is linked to from the following overview topics: Material Libraries.


Search for all occurrences

Detailed Description

See also:
Class ReferenceTarget, Class MtlBaseList, Class MtlBase, Class Interface.

Description:
This class is a library of MtlBase entries. To get a list of the currently loaded materials use:

MtlBaseLib& Interface::GetMaterialLibrary().

When you load a material library, you can enumerate all the materials that it contains. MtlBaseLib is subclassed off of MtlBaseList which is a Tab<MtlHandle>, so for example, you can do the following to work with each material:

for (int i=0; i<mlib.Count(); i++) { DoSomething(mlib[i]); }

For additional information on this class see the Advanced Topics section Working with Materials and Textures. All methods of this class are implemented by the system.

#include <imtl.h>

Inheritance diagram for MtlBaseLib:
Inheritance graph
[legend]

List of all members.

Public Member Functions

CoreExport  MtlBaseLib ()
virtual CoreExport  ~MtlBaseLib ()
virtual CoreExport SClass_ID  SuperClassID ()
  Retrieves a constant representing the type of the plugin.
virtual CoreExport Class_ID  ClassID ()
  Retrieves a constant that uniquely identifies the plugin class.
virtual CoreExport void  GetClassName (MSTR &s)
  Retrieves the name of the plugin class.
virtual CoreExport int  NumSubs ()
virtual CoreExport Animatable SubAnim (int i)
virtual CoreExport MSTR  SubAnimName (int i)
virtual CoreExport RefResult  AutoDelete ()
  Deletes the object when it has no more real dependents.
virtual CoreExport void  DeleteThis ()
  Deletes an instance of this class.
virtual CoreExport int  NumRefs ()
  Returns the total number of references this ReferenceMaker can hold.
virtual CoreExport RefTargetHandle  GetReference (int i)
  Returns the 'i-th' reference.
virtual CoreExport RefTargetHandle  Clone (RemapDir &remap)
  This method is used by 3ds Max to clone an object.
virtual CoreExport RefResult  NotifyRefChanged (Interval changeInt, RefTargetHandle hTarget, PartID &partID, RefMessage message)
  Receives and responds to messages.
virtual CoreExport IOResult  Save (ISave *isave)
  Called for saving data.
virtual CoreExport IOResult  Load (ILoad *iload)
  Called for loading data.
virtual CoreExport void  DeleteAll ()
virtual CoreExport void  Remove (MtlBase *m)
virtual CoreExport void  Add (MtlBase *m)
virtual CoreExport void  RemoveDuplicates ()

Protected Member Functions

virtual CoreExport void  SetReference (int i, RefTargetHandle rtarg)
  Stores a ReferenceTarget as its 'i-th' reference`.
int  GetMaterialCount () const
  Returns the count of materials under this category.
MtlBase GetMaterial (int i) const
  Get a pointer to the material with the given index.
MtlBase FindMaterial (const MCHAR *name) const
  Find the child material with the given name.
bool  AddMaterial (MtlBase *pMaterial)
  Add a material to the children list of this category.
void  RemoveMaterial (MtlBase *pMaterial)
  Removes the specified MtlBase from this category.
void  SetMaterial (int i, MtlBase *pMaterial)
void  SetMaterialCount (int count)

Protected Attributes

void *  mpReserved

Constructor & Destructor Documentation

CoreExport MtlBaseLib ( )
virtual CoreExport ~MtlBaseLib ( ) [virtual]
Remarks:
Destructor. All references are deleted.

Member Function Documentation

virtual CoreExport SClass_ID SuperClassID ( ) [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.

virtual CoreExport Class_ID ClassID ( ) [virtual]

Retrieves a constant that uniquely identifies the plugin class.

This method must return the unique ID for the plugin class. If two ClassIDs conflict, the system will only load the first conflicting one it finds. A program (gencid.exe) is provided to generate unique class id values.

Returns:
A class id that uniquely identifies a plugin class
See also:
Class ClassID, List of Class IDs.

Reimplemented from Animatable.

virtual CoreExport void GetClassName ( MSTR s ) [virtual]

Retrieves the name of the plugin class.

This name is usually used internally for debugging purposes. For Material plug-ins this method is used to put up the material "type" name in the Material Editor.

Parameters:
s Reference to a string filled in with the name of the plugin class

Reimplemented from ReferenceTarget.

virtual CoreExport int NumSubs ( ) [virtual]
Remarks:
The system uses a virtual array mechanism to access the sub-anims of a plug-in. This method returns the total number of sub-anims maintained by the plug-in. If a plug-in is using a parameter block to manage its parameters it should just return 1 for all the parameters directed by the parameter block.
Returns:
The number of sub-anims used by the plug-in.
Default Implementation:
{ return 0; }

Reimplemented from Animatable.

virtual CoreExport Animatable* SubAnim ( int  i ) [virtual]
Remarks:
This method returns a pointer to the 'i-th' sub-anim. If a plug-in is using a parameter block to manage all its parameters it should just return a pointer to the parameter block itself from this method. This method may return NULL so developers need to check the return value before calling other sub anim methods (such as SubAnimName()).
Parameters:
i This is the index of the sub-anim to return.
Default Implementation:
{ return NULL };

Reimplemented from Animatable.

virtual CoreExport MSTR SubAnimName ( int  i ) [virtual]
Remarks:
This method returns the name of the 'i-th' sub-anim to appear in track view. The system has no idea what name to assign to the sub-anim (it only knows it by the virtual array index), so this method is called to retrieve the name to display. Developer need to make sure the 'i-th' SubAnim() is non-NULL or this method will fail.
Parameters:
i The index of the parameter name to return
Returns:
The name of the 'i-th' parameter.

Reimplemented from Animatable.

virtual CoreExport RefResult AutoDelete ( ) [virtual]

Deletes the object when it has no more real dependents.

This function is called by 3ds Max in order to delete a plugin object when its last real dependent has been deleted. It also allows derived classes to control the lifetime of their instances. The default implementation of this method will drop the references this object makes to other objects, and if the undo system is engaged (holding) it will ensure that the deletion is undo/redo-able. Override this method only if you don't want instances of your plugin to be automatically deleted when the last reference to them is deleted. Most subclasses of class ReferenceTarget will not need to override this method. Plugins should call ReferenceTarget::MaybeAutoDelete() or ReferenceMaker::DeleteMe() to delete instances of plugin objects. For more information on how 3ds Max deletes reference targets, see ReferenceTarget::MaybeAutoDelete()

Returns:
Default implementation always returns REF_SUCCEED. Overwrites should also always return REF_SUCCEED.
Note:
Classes that overwrite this method to prevent deletion of their instances, should be deleted by calling ReferenceMaker::DeleteMe() on them.

Reimplemented from ReferenceTarget.

virtual CoreExport void DeleteThis ( ) [virtual]

Deletes an instance of this class.

3ds Max calls this method when it needs to delete a plugin object (an instance of a class derived from Animatable). Similarly, plugins that need to delete instances of an Animatable or a class directly derived from it via an Animatable pointer, should call this method instead of calling directly operator delete. Following these rules will ensure that the same memory manager is used to allocate and deallocate the object. The default implementation of this method deletes the object. Plugin instances that never need to be deleted from the heap can overwrite this method to do nothing.

Note:
See the method ClassDesc::Create() for details on how Max allocates plugin objects.
See ReferenceMaker::DeleteMe() and ReferenceTarget::MaybeAutoDelete() for information on how plugin instances are deleted by the system.
Remarks:
See Memory Allocation.

See also:
Plugin DLL Functions, Class ClassDesc.

Reimplemented from Animatable.

virtual CoreExport int NumRefs ( ) [virtual]

Returns the total number of references this ReferenceMaker can hold.

The plugin implements this method to indicate the total number of of references it can make. This includes all references whether they are NULL (inactive) or non-NULL (active) at the time when this method is called. A plugin can hold a variable number of references, thus the return value of this method is not to be cached and reused by client code.

Returns:
The total number of references this plugin can hold. The default implementation is return 0.

Reimplemented from ReferenceMaker.

virtual CoreExport RefTargetHandle GetReference ( int  i ) [virtual]

Returns the 'i-th' reference.

The plugin implements this method to return its 'i-th' reference. The plug-in simply keeps track of its references using an integer index for each one. This method is normally called by the system.

Parameters:
i - The index of the reference to retrieve. Valid values are from 0 to NumRefs()-1.
Returns:
The reference handle of the 'i-th' reference. Note that different calls to this method with the same 'i' value can result in different reference handles being retrieved, as the plugin changes the scene objects it references as its 'i-th' reference.

Reimplemented from ReferenceMaker.

virtual CoreExport void SetReference ( int  i,
RefTargetHandle  rtarg 
) [protected, virtual]

Stores a ReferenceTarget as its 'i-th' reference`.

The plugin implements this method to store the reference handle passed to it as its 'i-th' reference. In its implementation of this method, the plugin should simply assign the reference handle passed in as a parameter to the member variable that holds the 'i-th' reference. Other reference handling methods such as ReferenceMaker::DeleteReference(), or ReferenceMaker::ReplaceReference() should not be called from within this method. The plugin itself or other plugins should not call this method directly. The system will call this method when a new reference is created or an existing one is replaced by calling ReferenceMaker::ReplaceReference().

Parameters:
i - The index of the reference to store. Valid values are from 0 to NumRefs()-1.
rtarg - The reference handle to store.

Reimplemented from ReferenceMaker.

virtual CoreExport RefTargetHandle Clone ( RemapDir remap ) [virtual]

This method is used by 3ds Max to clone an object.

See also:
CloneRefHierarchy(), class RemapDir This method is called by 3ds Max to have the plugin clone itself. The plug-in's implementation of this method should copy both the data structure and all the data residing in the data structure of this reference target. The plugin should clone all its references as well. Also, the plug-in's implementation of this method must call BaseClone(). In order for classes derived from this class to clone cleanly, the Clone method should just create the new instance, and then call an implementation of BaseClone that clones the references and copies any other necessary data. For example:
            class MyDerivedPlugin
                : public MyBasePlugin
            {
                const int MY_REFERENCE = 1;

                ReferenceTarget* Clone(RemapDir& remap)
                {
                    ReferenceTarget* result = new MyDerivedPlugin();
                    BaseClone(this, result, remap);
                    return result;
                }

                void BaseClone(ReferenceTarget* from, ReferenceTarget* to, RemapDir& remap)
                {
                    if (!to || !from || from == to)
                        return;    
                    MyBasePlugin::BaseClone(from, to, remap);
                    to->ReplaceReference(MY_REFERENCE, remap->CloneRef(from->GetReference(MY_REFERENCE)));
                }
            };

This method should not be directly called by plug-ins. Instead, either RemapDir::CloneRef() or CloneRefHierachy() should be used to perform cloning. These methods ensure that the mapping from the original object to the clone is added to the RemapDir used for cloning, which may be used during backpatch operations

Note:
See the remarks in method BaseClone() below.
Parameters:
remap - A RemapDir instance used for remapping references during a Clone.
Returns:
A pointer to the cloned item.

Reimplemented from ReferenceTarget.

virtual CoreExport RefResult NotifyRefChanged ( Interval  changeInt,
RefTargetHandle  hTarget,
PartID partID,
RefMessage  message 
) [virtual]

Receives and responds to messages.

A plugin which makes references must implement a method to receive and respond to messages broadcast by its dependents. This is done by implementing NotifyRefChanged(). The plugin developer usually implements this method as a switch statement where each case is one of the messages the plugin needs to respond to. The Method StdNotifyRefChanged calls this, which can change the partID to new value. If it doesn't depend on the particular message& partID, it should return REF_DONTCARE.

  • For developer that need to update a dialog box with data about an object you reference note the following related to this method: This method may be called many times. For instance, say you have a dialog box that displays data about an object you reference. This method will get called many time during the drag operations on that object. If you updated the display every time you'd wind up with a lot of 'flicker' in the dialog box. Rather than updating the dialog box each time, you should just invalidate the window in response to the NotifyRefChanged() call. Then, as the user drags the mouse your window will still receive paint messages. If the scene is complex the user may have to pause (but not let up on the mouse) to allow the paint message to go through since they have a low priority. This is the way many windows in 3ds Max work.
Parameters:
changeInt - This is the interval of time over which the message is active. Currently, all plug-ins will receive FOREVER for this interval.
hTarget - This is the handle of the reference target the message was sent by. The reference maker uses this handle to know specifically which reference target sent the message.
partID - This contains information specific to the message passed in. Some messages don't use the partID at all. See the section List of Reference Messages for more information about the meaning of the partID for some common messages.
message - The message parameters passed into this method is the specific message which needs to be handled.
Returns:
The return value from this method is of type RefResult. This is usually REF_SUCCEED indicating the message was processed. Sometimes, the return value may be REF_STOP. This return value is used to stop the message from being propagated to the dependents of the item.

Implements ReferenceMaker.

virtual CoreExport IOResult Save ( ISave isave ) [virtual]

Called for saving data.

Called by the system to allow the plugin to save its data.

Parameters:
isave - This pointer may be used to call methods to write data to disk. See the section on Loading and Saving for an overview of the load/save process.
Returns:
The default implementation is return IO_OK.
  • IO_OK means the result was acceptable, with no errors.
  • IO_ERROR This should be returned if an error occurred.

Reimplemented from ReferenceMaker.

virtual CoreExport IOResult Load ( ILoad iload ) [virtual]

Called for loading data.

Called by the system to allow the plug-in to load its data. See the section on Loading and Saving for an overview of the load - save process.

Parameters:
iload - This interface pointer may be used to call methods to read data from disk.
Returns:
The default implementation is return IO_OK.
  • IO_OK means the result was acceptable, with no errors.
  • IO_ERROR This should be returned if an error occurred.

Reimplemented from ReferenceMaker.

virtual CoreExport void DeleteAll ( ) [virtual]
Remarks:
Removes all MtlBases from the library and deletes all references.
virtual CoreExport void Remove ( MtlBase m ) [virtual]
Remarks:
Removes the specified MtlBase from the library.
Parameters:
MtlBase *m

The MtlBase to remove.
virtual CoreExport void Add ( MtlBase m ) [virtual]
Remarks:
Adds the specified MtlBase to the library.
Parameters:
MtlBase *m

The MtlBase to add.
virtual CoreExport void RemoveDuplicates ( ) [virtual]
Remarks:
Removes all duplicate MtlBases from the library.
int GetMaterialCount ( ) const [protected]

Returns the count of materials under this category.

MtlBase* GetMaterial ( int  i ) const [protected]

Get a pointer to the material with the given index.

Precondition:
i must be greater than or equal to 0 and less than the count of materials.
Parameters:
[in] i - The index of the material.
Returns:
The pointer to the material.
MtlBase* FindMaterial ( const MCHAR *  name ) const [protected]

Find the child material with the given name.

Precondition:
name must not be NULL and must points to a string which is NULL terminated.
Parameters:
[in] name - The name of the child material to find.
Returns:
The pointer to the found child material.
bool AddMaterial ( MtlBase pMaterial ) [protected]

Add a material to the children list of this category.

Parameters:
[in] pMaterial - The material to add to this category. Can be NULL.
Returns:
true if the material is succeesfully added to this category, false otherwise.
void RemoveMaterial ( MtlBase pMaterial ) [protected]

Removes the specified MtlBase from this category.

Parameters:
[in] pMaterial - The MtlBase to remove. Can be NULL.
void SetMaterial ( int  i,
MtlBase pMaterial 
) [protected]
void SetMaterialCount ( int  count ) [protected]

Member Data Documentation

void* mpReserved [protected]

MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib
MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib MtlBaseLib