# HG changeset patch # User John Tsiombikas # Date 1376795403 -10800 # Node ID 01278d9b2d5e01c4d213268f9f493a6bc4046594 initial commit diff -r 000000000000 -r 01278d9b2d5e igame_test.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/igame_test.sln Sun Aug 18 06:10:03 2013 +0300 @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "igame_test", "igame_test.vcxproj", "{D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Debug|Win32.ActiveCfg = Debug|Win32 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Debug|Win32.Build.0 = Debug|Win32 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Debug|x64.ActiveCfg = Debug|x64 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Debug|x64.Build.0 = Debug|x64 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Release|Win32.ActiveCfg = Release|Win32 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Release|Win32.Build.0 = Release|Win32 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Release|x64.ActiveCfg = Release|x64 + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 000000000000 -r 01278d9b2d5e igame_test.vcxproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/igame_test.vcxproj Sun Aug 18 06:10:03 2013 +0300 @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D5C9D05D-65D0-4BBD-ABAB-BF2134DC3947} + Win32Proj + igame_test + + + + DynamicLibrary + true + Unicode + v110 + + + DynamicLibrary + true + Unicode + v110 + + + DynamicLibrary + false + true + Unicode + v110 + + + DynamicLibrary + false + true + Unicode + v110 + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;IGAME_TEST_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;IGAME_TEST_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Windows + true + core.lib;maxutil.lib;IGame.lib;%(AdditionalDependencies) + + + copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)\plugins\igame_test.dle" + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;IGAME_TEST_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;IGAME_TEST_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Windows + true + true + true + core.lib;maxutil.lib;IGame.lib;%(AdditionalDependencies) + + + copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)\plugins\igame_test.dle" + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 01278d9b2d5e igame_test.vcxproj.filters --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/igame_test.vcxproj.filters Sun Aug 18 06:10:03 2013 +0300 @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff -r 000000000000 -r 01278d9b2d5e src/test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test.cc Sun Aug 18 06:10:03 2013 +0300 @@ -0,0 +1,253 @@ +#include +#include +#include +#include +#include +#include "max.h" +#include "impexp.h" // SceneExport +#include "iparamb2.h" // ClassDesc2 +#include "plugapi.h" +#include "IGame.h" +#include "IGameExport.h" +#include "IConversionmanager.h" + + +#pragma comment (lib, "core.lib") +#pragma comment (lib, "geom.lib") +#pragma comment (lib, "gfx.lib") +#pragma comment (lib, "mesh.lib") +#pragma comment (lib, "maxutil.lib") +#pragma comment (lib, "maxscrpt.lib") +#pragma comment (lib, "paramblk2.lib") +#pragma comment (lib, "msxml2.lib") +#pragma comment (lib, "igame.lib") +#pragma comment (lib, "comctl32.lib") + + +static FILE *logfile; +static HINSTANCE hinst; + +class TestExporter : public SceneExport { +public: + IGameScene *igame; + + int ExtCount(); + const TCHAR *Ext(int n); + const TCHAR *LongDesc(); + const TCHAR *ShortDesc(); + const TCHAR *AuthorName(); + const TCHAR *CopyrightMessage(); + const TCHAR *OtherMessage1(); + const TCHAR *OtherMessage2(); + unsigned int Version(); + void ShowAbout(HWND win); + + int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); + + bool export_materials(FILE *fp); +}; + + +int TestExporter::ExtCount() +{ + return 1; +} + +const TCHAR *TestExporter::Ext(int n) +{ + return L"txt"; +} + +const TCHAR *TestExporter::LongDesc() +{ + return L"Test exporter file"; +} + +const TCHAR *TestExporter::ShortDesc() +{ + return L"Test exporter"; +} + +const TCHAR *TestExporter::AuthorName() +{ + return L"John Tsiombikas"; +} + +const TCHAR *TestExporter::CopyrightMessage() +{ + return L"Public domain"; +} + +const TCHAR *TestExporter::OtherMessage1() +{ + return L"other1"; +} + +const TCHAR *TestExporter::OtherMessage2() +{ + return L"other2"; +} + +unsigned int TestExporter::Version() +{ + return 10; +} + +void TestExporter::ShowAbout(HWND win) +{ + MessageBoxA(win, "TestExporter plugin", "About this plugin", 0); +} + +int TestExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, + BOOL non_interactive, DWORD opt) +{ + char fname[512]; + wcstombs(fname, name, sizeof fname - 1); + + FILE *fp = fopen(fname, "wb"); + if(!fp) { + fprintf(logfile, "failed to open %s for writting: %s", fname, strerror(errno)); + return IMPEXP_FAIL; + } + + if(!(igame = GetIGameInterface())) { + fprintf(logfile, "failed to get the igame interface\n"); + fclose(fp); + return IMPEXP_FAIL; + } + IGameConversionManager *cm = GetConversionManager(); + cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); + igame->InitialiseIGame(); + igame->SetStaticFrame(0); + + export_materials(fp); + + fclose(fp); + + return IMPEXP_SUCCESS; +} + +bool TestExporter::export_materials(FILE *fp) +{ + IGameProperty *prop; + + int num_mtl = igame->GetRootMaterialCount(); + fprintf(fp, "number of materials: %d\n", num_mtl); + + for(int i=0; iGetRootMaterial(i); + if(mtl) { + Point3 diffuse(1, 1, 1); + Point3 specular(0, 0, 0); + float shin = 1.0, sstr = 1.0; + char name[512] = "unnamed"; + + const MCHAR *wname = mtl->GetMaterialName(); + if(wname) { + wcstombs(name, wname, sizeof name - 1); + } + + if((prop = mtl->GetDiffuseData())) { + prop->GetPropertyValue(diffuse); + } + if((prop = mtl->GetSpecularData())) { + prop->GetPropertyValue(specular); + } + if((prop = mtl->GetSpecularLevelData())) { + prop->GetPropertyValue(sstr); + } + if((prop = mtl->GetGlossinessData())) { + prop->GetPropertyValue(shin); + } + + fprintf(fp, "Material %d (%s):\n", i, name); + fprintf(fp, " diffuse: %f %f %f\n", diffuse[0], diffuse[1], diffuse[2]); + fprintf(fp, " specular: %f %f %f\n", specular[0] * sstr, specular[1] * sstr, specular[2] * sstr); + fprintf(fp, " shininess: %f\n", shin * 100.0); + + for(int j=0; jGetNumberOfTextureMaps(); j++) { + IGameTextureMap *tex = mtl->GetIGameTextureMap(j); + const MCHAR *wfname = tex->GetBitmapFileName(); + if(wfname) { + char fname[512]; + wcstombs(fname, wfname, sizeof fname - 1); + fprintf(fp, " texture%d: %s\n", j, fname); + } + } + } + } + + return true; +} + +// ------------------------------------------ + +class TestClassDesc : public ClassDesc2 { +public: + int IsPublic() { return TRUE; } + void *Create(BOOL loading = FALSE) { return new TestExporter; } + const TCHAR *ClassName() { return L"TestExporter"; } + SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; } + Class_ID ClassID() { return Class_ID(0x77050f0d, 0x7d4c5ab5); } + const TCHAR *Category() { return L"Mutant Stargoat"; } + + const TCHAR *InternalName() { return L"TestExporter"; } + HINSTANCE HInstance() { return hinst; } +}; + +static TestClassDesc class_desc; + +BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved) +{ + if(reason == DLL_PROCESS_ATTACH) { + hinst = inst_handle; + DisableThreadLibraryCalls(hinst); + } + return TRUE; +} + +extern "C" { + +__declspec(dllexport) const TCHAR *LibDescription() +{ + return L"test exporter"; +} + +__declspec(dllexport) int LibNumberClasses() +{ + return 1; +} + +__declspec(dllexport) ClassDesc *LibClassDesc(int i) +{ + return i == 0 ? &class_desc : 0; +} + +__declspec(dllexport) ULONG LibVersion() +{ + return Get3DSMAXVersion(); +} + +__declspec(dllexport) int LibInitialize() +{ + static char path[1024]; + + SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path); + strcat(path, "/testexp.log"); + + if((logfile = fopen(path, "w"))) { + setvbuf(logfile, 0, _IONBF, 0); + } + return TRUE; +} + +__declspec(dllexport) int LibShutdown() +{ + if(logfile) { + fclose(logfile); + logfile = 0; + } + return TRUE; +} + +} // extern "C" \ No newline at end of file