| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
From
3D Studio Max to Direct3D, Part 2: This time we're going to talk about how to develop a MAX plug-in. Enclosed with this article are two samples of a simple Utility plug-in -- one for the Visual C++ 4.x / Max 1.x, and the other one for Visual C++ 5.x / Max x.x. These samples will give you an overview of an exporter plug-in's skeleton. To save time, you can personalize them for your own Utility plug-ins. plug-ins Overview MAX
offers many types of plug-ins. In MAX, a plug-in is a DLL which is
explicitly loaded during the MAX's startup. Every type of plug-in has a
specific file extension (i.e. .DLU for Utility plug-ins, .DLM for Modifier
plug-ins, .DLO for procedural Object plug-ins, etc
). This extension
is used by MAX to differentiate common DLLs from plug-ins. Windows DLLs A Dynamic Linked Library can be seen as an executable (.EXE) which contains functions callable by another executable. Like an executable, it can also contain its own resources (dialog template, string, icons, etc ). Standard DLLs only give you the possibility to export C-like functions. With Visual C++'s MFCs you can create a new kind of DLL called 'MFC Extension' where it's possible to export C++ classes. When a client program uses a DLL's functions, the DLL's header file must be included in the .cpp files that use the functions, and the DLL's library (file extension .lib) must be linked to the project. Only functions that were declared to exportation can be used by a client program. Exportation declarations can be done using .def file (for both regular and extension DLLs) or using Microsoft's specific tokens (for extension DLLs only). As MAX is
a pure Win32 program, DLLs are not supposed to use MFC and must be of
the Regular type only. Using the .def file of your plug-in's project,
four functions have to be declared in exportation. You'll have to edit
the .def to make it looks like : EXPORTS LibDescription @1 LibNumberClasses @2 LibClassDesc @3 LibVersion @4 SECTIONS .data READ WRITE Each exported
functions are associated with a number that will be used to make the dynamic
link when the client (MAX) will call the DLL's functions. The most important
function is the LibClassDesc().
It's used to returned an object that will be used by MAX to create
the plug-in. Typical steps to create a MFC based utility plug-in There's
two ways to create a MFC based plug-in: the first with static linking of
MFC DLLs, and the second with shared MFC DLLs. Both have advantages and
disadvantages. For static linking, the MFC functions and resources will
be statically linked to your plug-in. This will, however, make your
plug-in bigger in size. The advantage is that you can use MFC transparently,
like a typical MFC program. For shared MFC DLLs (also called dynamic linking
of MFC DLLs), the advantage is you keep a short DLL, but as your plug-in
is also a DLL, the utilization of MFC resources needs some extra code,
as nested DLLs are not managed transparently concerning resources.
I'll explain the first method only, as its implementation is easier, and
more understandable. Your plug-in will increase in size by about 100kb
more than with the second method.
Once you succeed at compiling your plug-in, you have to test it, and if somehow it hangs (it happens, sometimes ) you may want to debug to see what's going on. Debugging
is an inevitable step of programming, and even if your program doesn't
hang, it's always interesting to trace a program to see how everything
works. Debugging a MAX's plug-in is not as easy as debugging a program.
Normally, you choose the "Debug" compilation mode when you're in the debugging
phase of your project, but it's not something you can do with MAX's plug-ins.
Visual C++ proposes two compilation modes : Debug and Release. Typically,
you develop your project using the Debug Mode, because it offers many
advantages like source level debugging, special memory management, crash
protection/checking, etc
Once you finish your project, you compile
it using the Release Mode which optimizes your code and suppresses debug
information and debug purpose checking to make your project shorter and
faster at execution.
As the
Debug Compilation Mode can't be used for the plug-in, you can remove it
by repeating Step 1, selecting the Debug Mode of your plug-in, and clicking
the "Remove" button. Some features that were available in Debug Mode won't
be used with this mode:
As the setting was taken from the Release Mode, the Preprocessing define "NDEBUG" is declared. You can remove it ("C/C++" tab of the Project setting panel, "Preprocessor definitions") and set a new define (ie "SPECIALMAX" ) The Sample There's
two zip files :
For your
projects to be compiled correctly, you'll have to perform some slight
changes:
The sample
demonstrates a little plug-in that provides basic information about the
node you selected. I strongly recommend you look at every line, to understand
how the MAX's basic functions work.
|
|
|