I will not use the class technique for creating the plugin.
I wrote a Metasequoia Python script [link] to import MilkShape 3D *.ms3d files and will write a plugin to do the same.
Plugins have access to more of Metasequoia’s inbuilt functions than scripts.
MilkShape 3D released a *.ms3d viewer with C++ source code [link].
We will use the *.ms3d file loading code from the viewer in our plugin to read the *.ms3d file so download msViewer2.zip and extract it somewhere.
See the previous posts for the details about the following steps.
Add a new project to the mqsdk solution.
Choose C++ Win32 project, give it a suitable name and click OK.
Click Application Settings, select DLL, Empty project and click Finish.
Open the msViewer\src folder in File Explorer and copy the following files into the project folder.
- msModel.h
- msModel.cpp
- mathlib.h
- mathlib.cpp
In Visual Studio add the files (existing items) to the project.
Add MQInit.cpp (existing item) to the project.
Add a new blank *.cpp file to the project. We will write our plugin code in this file.
Set the following properties in the project’s Property Pages.
- If a 64 bit *.dll is required use Configuration Manager to change the platform
- For All Configurations set the Output Directory and Intermediate directory
- For All Configurations set the Character Set to Multi-Byte Character Set
- For All Configurations set the Additional Include Directories to “..”
- For Debug Configuration set the Debugging Command to path to Metaseq.exe
- For Debug Configuration set a Post-Build Event to copy *.dll to Import folder
If you don’t set the Post-Build Event you will have to copy the *.dll to the Metasequoia\Plugins\Import folder in File Explorer every time you build the project.
For reference open ImportDXF.cpp in the editor.
Copy and paste the define, includes and function declaration into our plugin’s blank source file.
Delete #include “Strings.h” since we do not need it, add #include “msModel.h” so we can use the functions from it and rename the function LoadMS3D.
Next in ImportDXF is the DllMain function. We don’t need to initialise any variables when the *.dll is loaded so we don’t need to add this function to our plugin.
Add the required MQGetPlugInID function and change the Product and ID numbers to the ones you chose for yourself.
Next add the required MQGetPlugInName function and change the text to what you want displayed in the Help>About Plug-ins dialog.
Next add the required MQGetPlugInType function and make sure the type is MQPLUGIN_TYPE_IMPORT.
Next add the MQEnumFileType function which is required for Import plugins and change the text to the file type you are importing.
Next add the MQEnumFileExt function which is required by Import plugins and change the extension to your file extension.
Next add the MQImportFile function which is specifically required for Import plugins.
Change the name of the function called in this function to the function name you declared at the top of the file.
Now we need to write the LoadMS3D function to do the importing of the file.
We need to study the msViewer code to see how the msModel class is used.
We need to create a variable of the msModel type and then call the msModel::Load method.
To begin with we will only write code to load the model into an msModel object and see if the plugin builds and test successfully.
Build the project and if successful place a breakpoint on line 52 inside the LoadMS3D function.
You place a breakpoint by clicking in the gutter area of the text editor’s left margin. A red dot indicates a breakpoint.
Breakpoints only work with the Debug configuration and only when you use the debugger.
Run the debugger to start Metasequoia.
Metasequoia should report any problems loading our plugin on start up.
Failing to add MQInit.cpp to the project causes the error shown below.
If the plugin loads okay open a MilkShape 3D *.ms3d file.
The debugger should pause Metasequoia and return to Visual Studio at our breakpoint.
We have paused the plugin before the *.ms3d file is loaded so we can execute the lines one by one and see whether the *.ms3d data is saved in the variable, model.
Click DEBUG>Step Over or press F10 to execute one line of code.
Repeat until the yellow arrow is at line 55.
When line 54 was executed the *.ms3d file was read and model was populated with the data.
You can see the data in model by looking at the Locals window below the editor.
We know the file loaded since the next line to be executed will return TRUE.
Stop the debugger and return to the editor.
You can remove the breakpoint by clicking on the red dot.
Now we have to write code to transfer the model data to a Metasequoia Object.
Rather than write the code directly in the LoadMS3D function I will write it in another function that will be called in LoadMS3D.
Because I am writing the new function below LoadMS3D in which it is called I have to declare it in the file somewhere above LoadMS3D.
I’ll post the completed function without explanation of the code.
I basically copied the ImportDXF code, used the SDK API reference and studied msModel.h.
As for the C++ I had to use trial and error a bit because my knowledge of classes and pointers is not good.
At this stage the plugin only imports the vertices and faces but since the msModel class stores materials and groups the plugin could be expanded to use those as well.
I expanded the plugin to use the UVs and materials from the *.ms3d and also to show a dialog for adjusting the scale. The code can be found at GitHub [link].
prev | next | first
No comments:
Post a Comment