Getting started with 3DS MAX plug-in Development written by old wolf

Source: Internet
Author: User

FW: http://www.enginedev.net/read.php? Tid-17.html

 

[Original] newbie to 3dsmax plug-in development Author: old wolf
Email: cgwolver@163.com
QQ: 4197680024

I try to make the topic easier to understand, because the plug-in may not only be a programmer :)
The so-called plug-in is actually a dynamic link library. In Windows, it is a DLL. Open the Autodesk/3DS MAX 9/stdplugs folder and you will see a lot of files named dlu, DLO, and so on. In fact, this is the name changed by DLL. The essence is DLL. When the host is running, all files with the dlxx extension under this folder will be loaded. Therefore, you can use any DLL creation method to generate it, such as Win32 DLL project or mfc dll project. I prefer the MFC DLL project, you can easily use the MFC function. When using the mfc dll project in the 3dsmax plug-in, you need to pay attention to some issues, which will be described later.

If you want to quickly write plug-ins, the VC Wizard provided by maxsdk is usually the easiest way to create a specific plug-in Framework Program. Here we will briefly describe how to set 3 dsmax vc Wizard:

After three DSMAX products are installed, you must install maxsdk. the SDK and a large number of samples are installed on the complete installation version of the DVD. The pluginwizard path is under Autodesk/3DS MAX 2009 SDK/maxsdk/howto/3dsmaxpluginwizard, and the readme.txt file is included, open 3dsmaxpluginwizard in a text editor. vsz, I installed 3dsmax2009. The content of this vsz file is as follows:

Vswizard 7.0
Wizard = vswizard. vswizardengine.8.0

Param = "wizard_name = 3 dsmaxpluginwizard"
Param = "absolute_path = C:/dev/P4/Gouda/3 dswin/src/maxsdk/howto/3 dsmaxpluginwizard"
Param = "fallback_lcid = 1033"

Change the path of absolute_path to D:/Autodesk/3DS MAX 2009 SDK/maxsdk/howto/3 dsmaxpluginwizard, which is the original path of the file you copied.

In this case, use vc8 to create a project, select VC ++, and you will see a 3DS MAX plugin wizard list item. Then, follow the prompts to create a basic plug-in framework step by step.

Here I want to talk more about how to create 3 DSMAX plugins using the custom DLL project method. I do not like to use ready-made things. I always like what I do myself, this understanding is also profound.

3 dsmaxplug-in, there are several standard export guides. When 3dsmax.exe loads the plug-in, use the getprocaddress API to find the predefined standard interfaces, then call a libclassdesc interface to create a user-defined object instance, similar to the "Abstract Factory" Method

3. Standard export functions that must be defined in the DSMAX plug-in:
# Define dllexport_api _ declspec (dllexport)

// Plug-in description
Dllexport_api const tchar * libdescription ()
{
Loadstring (ids_libdescription );
}
// There are several plug-ins in this DLL
Dllexport_api int libnumberclasses ()
{
Return 1;
}
// Obtain the plug-in blocks. Use 3dsmax.exe to create your plug-in class instance.
Dllexport_api classdesc * libclassdesc (int I)
{
Switch (I)
{
Case 0: Return getmyclassdesc ();
Default: Return 0;
}
}
// Libversionis used to match the version of the plug-in with the client 3dsmax.exe.
Dllexport_api ulong libversion ()
{
Return version_3dsmax;
}

You don't need to talk about how to create a DLL project in VC. The point is that the export function must be modified with _ declspec (dllexport, you also need to list the export function names in the def file as follows:
Assume that the file name of an export plug-in is sampleexporter.
// Sampleexporter. Def
Library sampleexporter
Exports
Libdescription @ 1
Libnumberclasses @ 2
Libclassdesc @ 3
Libversion @ 4
Sections
. Data read write

The following describes the getmyclassdesc () function...

# Define sampleexporter_class_id class_id (0xc2a1ee34, 0x832cc295) // This class_id is generated by Autodesk/3DS MAX 2009 SDK/maxsdk/help/getcid.exe without conflict.

// Sampleexporter is an export plug-in class inherited from sceneexport. sceneexport is a base class predefined by the SDK for implementing the export plug-in. You only need to inherit the plug-in from the user's write and export plug-in, then implement the corresponding pure virtual interface.
// The import plug-in is based on sceneexport, the auxiliary plug-in is based on utilityobj, And the create panel. For details, see type of plug-ins in 3DS max sdk programmer's sguide.
// Export doexportis the main interface for interaction between 3dsmax.exe and the export plug-in program. Select the file/export menu and select sampleexporter. The doexport function is displayed...
Class sampleexporter: Public sceneexport {
Public:
Static hwnd hparams;

Int extcount (); // number of extensions supported
Const tchar * ext (int n); // extension # N (I. e. "3DS ")
Const tchar * longdesc (); // long ASCII description (I. e. "Autodesk 3D Studio file ")
Const tchar * includesc (); // short ASCII description (I. e. "3D Studio ")
Const tchar * authorname (); // ASCII author name
Const tchar * copyrightmessage (); // ASCII copyright message
Const tchar * othermessage1 (); // other message #1
Const tchar * othermessage2 (); // other message #2
Unsigned int version (); // version number * 100 (I. e. v3.01 = 301)
Void showabout (hwnd); // show DLL's "about..." box

Bool supportsoptions (INT Ext, DWORD options );
Int doexport (const tchar * Name, expinterface * EI, interface * I, bool suppressprompts = false, DWORD Options = 0 );

// Constructor/destructor
Sampleexporter ();
~ Sampleexporter ();

};
// How does 3dsmax.exe establish a connection with the User-Defined plug-in is to obtain the necessary information required to create the plug-in object instance through the classdesc class below
Class sampleexporterclassdesc: Public classdesc2
{
Public:
Virtual int ispublic () {return true ;}
Virtual void * Create (bool/* loading = false */) {return New sampleexporter ();} // This is actually the "Abstract Factory" method, allowing users to provide an instance
Virtual const tchar * classname () {return getstring (ids_class_name );}
Virtual sclass_id superclassid () {return scene_export_class_id ;}
Virtual class_id classid () {return sampleexporter_class_id ;}
Virtual const tchar * category () {return getstring (ids_category );}
Virtual const tchar * internalname () {return _ T ("sampleexporter");} // returns fixed parsable name (scripter-visible name)
Virtual hinstance () {return hinstance;} // returns owning module handle
};

Static sampleexporterclassdesc expoertdesc;
Classdesc2 * getmyclassdesc () {return & expoertdesc ;}

// The following is the implementation code of the sampleexporter class.
Sampleexporter: sampleexporter ()
{
}
Sampleexporter ::~ Sampleexporter ()
{
}
Int sampleexporter: extcount ()
{
# Pragma message (todo ("returns the number of file name extensions supported by the plug-in ."))
Return 1;
}
Const tchar * sampleexporter: ext (int n)
{
# Pragma message (todo ("return the 'I-th' file name extension (I. e./" 3DS /")."))
Return _ T ("");
}

Const tchar * sampleexporter: longdesc ()
{
# Pragma message (todo ("Return long ASCII description (I. e./" Targa 2.0 image file /")"))
Return _ T ("");
}

Const tchar * sampleexporter: includesc ()
{
# Pragma message (todo ("Return short ASCII description (I. e./" Targa /")"))
Return _ T ("");
}
Const tchar * sampleexporter: authorname ()
{
# Pragma message (todo ("Return ASCII author name "))
Return _ T ("");
}
Const tchar * sampleexporter: copyrightmessage ()
{
# Pragma message (todo ("Return ASCII copyright message "))
Return _ T ("");
}
Const tchar * sampleexporter: othermessage1 ()
{
// Todo: return other message #1 if any
Return _ T ("");
}
Const tchar * sampleexporter: othermessage2 ()
{
// Todo: return other message #2 in any
Return _ T ("");
}
Unsigned int sampleexporter: Version ()
{
# Pragma message (todo ("Return version number * 100 (I. e. v3.01 = 301 )"))
Return 100;
}
Void sampleexporter: showabout (hwnd)
{
// Optional
}
Bool sampleexporter: supportsoptions (INT Ext, DWORD options)
{
# Pragma message (todo ("decide which options to support. Simply return true for each option supported by each extension the exporter supports ."))
Return true;
}
// This is the real export function entry. After you select export, it will be executed here
Int sampleexporter: doexport (const tchar * Name, expinterface * EI, interface * I, bool suppressprompts, DWORD options)
{
# Pragma message (todo ("implement the actual file export here and "))

If (! Suppressprompts)
Dialogboxparam (hinstance,
Makeintresource (idd_panel ),
Getactivewindow (),
Maxproject1optionsdlgproc, (lparam) This );

# Pragma message (todo ("Return true if the file is exported properly "))
Return false;
}

Now a basic plug-in framework has been built. The rest is to traverse the scenario node to implement your own data export function.
(End)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.