Skip to content

Commit

Permalink
Sketchfab publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
erich666 committed Mar 14, 2016
1 parent c5ab1af commit 61d58c9
Show file tree
Hide file tree
Showing 44 changed files with 7,597 additions and 69 deletions.
183 changes: 182 additions & 1 deletion Win/Mineways.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include "Mineways.h"
#include "ColorSchemes.h"
#include "ExportPrint.h"
#include "publishSkfb.h"
#include "XZip.h"
#include "lodepng.h"
#include <assert.h>
Expand Down Expand Up @@ -106,13 +107,16 @@ static int gTargetDepth=MIN_OVERWORLD_DEPTH; //how far down the depth is
static ExportFileData gExportPrintData;
static ExportFileData gExportViewData;
static ExportFileData gExportSchematicData;
static PublishSkfbData gSkfbPData;
// this one is set to whichever is active for export or import, 3D printing or rendering
static ExportFileData *gpEFD;

static int gOverworldHideStatus=0x0;

static wchar_t gCurrentDirectory[MAX_PATH];
static wchar_t gWorldPath[MAX_PATH];
LPTSTR filepath = new TCHAR[MAX_PATH];
LPTSTR tempdir = new TCHAR[MAX_PATH];

// low, inside, high for selection area, fourth value is minimum height found below selection box
static int gHitsFound[4];
Expand Down Expand Up @@ -198,6 +202,7 @@ static void setSlider( HWND hWnd, HWND hwndSlider, HWND hwndLabel, int depth, bo
static void syncCurrentHighlightDepth();
static void copyOverExportPrintData( ExportFileData *pEFD );
static int saveObjFile( HWND hWnd, wchar_t *objFileName, int printModel, wchar_t *terrainFileName, BOOL showDialog );
static int publishToSketchfab( HWND hWnd, wchar_t *objFileName, wchar_t *terrainFileName);
static void PopupErrorDialogs( int errCode );
static const wchar_t *removePath( const wchar_t *src );
static void initializeExportDialogData();
Expand Down Expand Up @@ -227,6 +232,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
UNREFERENCED_PARAMETER(lpCmdLine);

initializeExportDialogData();
// Initialize Skfb data
memset(&gSkfbPData, 0, sizeof(PublishSkfbData));

MSG msg;
HACCEL hAccelTable;
Expand Down Expand Up @@ -635,7 +642,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//#endif
}
}

// Reset Sketchfab path so that we rewrite obj/mtl/PNG + zip when publishing
deleteFile();
gSkfbPData.skfbFilePath = "";
SetHighlightState(gHighlightOn,gStartHiX,gTargetDepth,gStartHiZ,mx,gCurDepth,mz);
enableBottomControl( gHighlightOn, hwndBottomSlider, hwndBottomLabel, hwndInfoBottomLabel );
validateItems(GetMenu(hWnd));
Expand Down Expand Up @@ -1148,11 +1157,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

return 0;
}

// because gSameWorld gets set to 1 by loadWorld()
if (!gHoldSameWorld)
{
wchar_t title[MAX_PATH];
formTitle(gWorld,title);
sprintf_s(gSkfbPData.skfbName, "%ws", stripWorldName(gWorld));
SetWindowTextW(hWnd,title);
}
EnableWindow(hwndSlider,TRUE);
Expand Down Expand Up @@ -1197,11 +1208,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case IDM_CLOSE:
deleteFile();
DestroyWindow(hWnd);
break;
case IDM_TEST_WORLD:
gWorld[0] = 0;
gSameWorld = 0;
sprintf_s(gSkfbPData.skfbName, "TestWorld");
gotoSurface( hWnd, hwndSlider, hwndLabel);
loadWorld();
goto InitEnable;
Expand Down Expand Up @@ -1251,6 +1264,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
wchar_t title[MAX_PATH];
formTitle(gWorld,title);
sprintf_s(gSkfbPData.skfbName, "%ws", stripWorldName(gWorld));
SetWindowTextW(hWnd,title);
}
EnableWindow(hwndSlider,TRUE);
Expand Down Expand Up @@ -1468,6 +1482,41 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} // matches to "if ( saveOK )"
}
break;
case IDM_PUBLISH_SKFB:
if ( !gHighlightOn )
{
// we keep the export options ungrayed now so that they're selectable when the world is loaded
MessageBox( NULL, _T("Click and drag with your right mouse button to select an area to export."),
_T("Informational"), MB_OK|MB_ICONINFORMATION);
break;
}
// Force it to be an rendering export: Relative obj
gPrintModel=0;
gExportViewData.fileType=FILE_TYPE_WAVEFRONT_REL_OBJ;
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.hwndOwner=hWnd;
ofn.lpstrFile=gExportPath;
ofn.nMaxFile=MAX_PATH;

ofn.nFilterIndex=gExportViewData.fileType+1;
ofn.lpstrFileTitle=NULL;
ofn.nMaxFileTitle=0;
ofn.lpstrInitialDir=NULL;
ofn.Flags=OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

// Write zip in temp directory
GetTempPath(MAX_PATH, tempdir);

// OSX workaround since tempdir will not be ok
// TODO: find a better way to detect OSX + Wine vs Windows
if ( !PathFileExists(tempdir) )
{
swprintf_s(tempdir, MAX_PATH, L"\\tmp\\");
}
swprintf_s(filepath, MAX_PATH, L"%sMineways2Skfb", tempdir);
publishToSketchfab(hWnd, filepath, gSelectTerrain);
break;
case IDM_JUMPSPAWN:
gCurX=gSpawnX;
gCurZ=gSpawnZ;
Expand Down Expand Up @@ -2320,6 +2369,7 @@ static void validateItems(HMENU menu)
EnableMenuItem(menu,IDM_FILE_SAVEOBJ,MF_ENABLED);
EnableMenuItem(menu,IDM_FILE_PRINTOBJ,MF_ENABLED);
EnableMenuItem(menu,IDM_FILE_SCHEMATIC,MF_ENABLED);
EnableMenuItem(menu,IDM_PUBLISH_SKFB,MF_ENABLED);
}
else
{
Expand All @@ -2330,6 +2380,7 @@ static void validateItems(HMENU menu)
EnableMenuItem(menu,IDM_FILE_PRINTOBJ,MF_DISABLED);
EnableMenuItem(menu,IDM_FILE_SCHEMATIC,MF_DISABLED);
EnableMenuItem(menu,IDM_VIEW_JUMPTOMODEL,MF_DISABLED);
EnableMenuItem(menu,IDM_PUBLISH_SKFB,MF_DISABLED);
}
// has a save been done?
if (gExported)
Expand Down Expand Up @@ -2469,6 +2520,136 @@ static void copyOverExportPrintData( ExportFileData *pEFD )
}
}

int publishToSketchfab( HWND hWnd, wchar_t *objFileName, wchar_t *terrainFileName )
{
int on;
int retCode = 0;

PublishSkfbData* skfbPData = &gSkfbPData;
// set 'export for rendering' settings
gpEFD = &gExportViewData;
gOptions.exportFlags = 0x0;
gpEFD->flags = 0x0;

gOptions.pEFD = gpEFD;

// get selected zone bounds
GetHighlightState(&on, &gpEFD->minxVal, &gpEFD->minyVal, &gpEFD->minzVal, &gpEFD->maxxVal, &gpEFD->maxyVal, &gpEFD->maxzVal );

int miny = gpEFD->minyVal;
int maxy = gpEFD->maxyVal;

// set epd in skfbPDdata data
setPublishSkfbData(skfbPData);

// Open dialog and get user data
if ( !doPublishSkfb(hInst,hWnd) )
{
return 0;
}
// Get updated version of export data (api token, etc)
getPublishSkfbData(skfbPData);

// if user changed depths
if ( miny != gpEFD->minyVal || maxy != gpEFD->maxyVal )
{
// see if target did not change
if ( gTargetDepth <= gCurDepth )
{
gTargetDepth = gpEFD->minyVal;
gCurDepth = gpEFD->maxyVal;
}
else
{
gTargetDepth = gpEFD->maxyVal;
gCurDepth = gpEFD->minyVal;
}
}

// get zone bounds
SetHighlightState(on, gpEFD->minxVal, gpEFD->minyVal, gpEFD->minzVal, gpEFD->maxxVal, gpEFD->maxyVal, gpEFD->maxzVal );

// export all ellements for Skfb
gOptions.saveFilterFlags = BLF_WHOLE | BLF_ALMOST_WHOLE | BLF_STAIRS | BLF_HALF | BLF_MIDDLER | BLF_BILLBOARD | BLF_PANE | BLF_FLATTOP |
BLF_FLATSIDE | BLF_3D_BIT;

// Set options for Sketchfab publication. Need to determine best settings here, the user will not have the choice
gOptions.exportFlags |= EXPT_OUTPUT_MATERIALS | EXPT_OUTPUT_TEXTURE_IMAGES | EXPT_GROUP_BY_MATERIAL | EXPT_SKFB;

gOptions.exportFlags |=
(gpEFD->chkHollow[gpEFD->fileType] ? EXPT_HOLLOW_BOTTOM : 0x0) |
((gpEFD->chkHollow[gpEFD->fileType] && gpEFD->chkSuperHollow[gpEFD->fileType]) ? EXPT_HOLLOW_BOTTOM|EXPT_SUPER_HOLLOW_BOTTOM : 0x0);

gOptions.exportFlags |= EXPT_OUTPUT_OBJ_GROUPS; // export groups
gOptions.exportFlags |= EXPT_OUTPUT_OBJ_MATERIAL_PER_TYPE; // the norm, instead of single material
gOptions.exportFlags |= EXPT_OUTPUT_OBJ_FULL_MATERIAL; // Full material (output the extra values)
gOptions.exportFlags |= EXPT_OUTPUT_TEXTURE_IMAGES; // Export block full texture
gOptions.exportFlags |= EXPT_OUTPUT_OBJ_REL_COORDINATES; // OBj relative coordinates
gOptions.exportFlags |= EXPT_BIOME; // Use biome for export. Currently only the biome at the center of the zone is supported

// Generate files
FileList outputFileList;
outputFileList.count = 0;
if ( on ) {

draw();
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
gpEFD->radioScaleToHeight = 1;
gpEFD->radioScaleByCost = 0;
gpEFD->chkCreateModelFiles[gpEFD->fileType] = 0;
// if skfbFilePath is empty, that means that it has not been created yet or selection has changed
if (skfbPData->skfbFilePath.empty()){
int errCode = SaveVolume(objFileName, gpEFD->fileType, &gOptions, gWorld, gCurrentDirectory,
gpEFD->minxVal, gpEFD->minyVal, gpEFD->minzVal, gpEFD->maxxVal, gpEFD->maxyVal, gpEFD->maxzVal,
updateProgress, terrainFileName, &outputFileList, (int)gMajorVersion, (int)gMinorVersion);

wchar_t wcZip[MAX_PATH];

swprintf_s(wcZip, MAX_PATH, L"%s.zip", outputFileList.name[0]);
DeleteFile(wcZip);

HZIP hz = CreateZip(wcZip,0,ZIP_FILENAME);
for ( int i = 0; i < outputFileList.count; i++ )
{
const wchar_t *nameOnly = removePath( outputFileList.name[i] ) ;

if (*updateProgress)
{ (*updateProgress)(0.90f + 0.10f*(float)i/(float)outputFileList.count);}

ZipAdd(hz,nameOnly, outputFileList.name[i], 0, ZIP_FILENAME);

// delete model files if not needed
if ( !gpEFD->chkCreateModelFiles[gpEFD->fileType] )
{
DeleteFile(outputFileList.name[i]);
}
}
CloseZip(hz);

if (*updateProgress)
(*updateProgress)(1.0f);

if ( errCode != MW_NO_ERROR )
{
PopupErrorDialogs( errCode );
}

// Set filepath to skfb data
std::wstring file(wcZip);
std::string filepath(file.begin(), file.end());
skfbPData->skfbFilePath = filepath;
setPublishSkfbData(skfbPData);
}

uploadToSketchfab(hInst, hWnd);
if (*updateProgress)
(*updateProgress)(0.0f);
}

return retCode;
}

// returns number of files written on successful export, 0 files otherwise.
static int saveObjFile( HWND hWnd, wchar_t *objFileName, int printModel, wchar_t *terrainFileName, BOOL showDialog )
{
Expand Down
Binary file modified Win/Mineways.rc
Binary file not shown.
32 changes: 21 additions & 11 deletions Win/Mineways.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,37 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;USE_SSLEAY;CURL_STATICLIB;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>..\dependencies;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib</IgnoreSpecificDefaultLibraries>
<AdditionalDependencies>libcurld.lib;ws2_32.lib;wldap32.lib;libeay32MTd.lib;ssleay32MTd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>libcmtd.lib</IgnoreSpecificDefaultLibraries>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>..\dependencies\curl\lib\win32;..\dependencies\openssl\lib\win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;MINEWAYS_X64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;CURL_STATICLIB;USE_SSLEAY ;_DEBUG;_WINDOWS;MINEWAYS_X64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>..\dependencies;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMTD.lib</IgnoreSpecificDefaultLibraries>
<AdditionalDependencies>libcurld.lib;ws2_32.lib;wldap32.lib;libeay32MTd.lib;ssleay32MTd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat64.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>libcmtd.lib</IgnoreSpecificDefaultLibraries>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>..\dependencies\curl\lib\win64;..\dependencies\openssl\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -121,17 +125,20 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;USE_SSLEAY;CURL_STATICLIB;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>..\dependencies;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libcurl.lib;ws2_32.lib;wldap32.lib;libeay32MT.lib;ssleay32MT.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>..\dependencies\curl\lib\win32;..\dependencies\openssl\lib\win32;</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -141,22 +148,25 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;MINEWAYS_X64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;CURL_STATICLIB;USE_SSLEAY ;_WINDOWS;MINEWAYS_X64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>..\dependencies;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib</IgnoreSpecificDefaultLibraries>
<AdditionalDependencies>libcurl.lib;ws2_32.lib;wldap32.lib;libeay32MT.lib;ssleay32MT.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;version.lib;zlibstat64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;</IgnoreSpecificDefaultLibraries>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<AdditionalLibraryDirectories>..\dependencies\curl\lib\win64;..\dependencies\openssl\lib\win64;</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="sketchfab_banner.bmp" />
<None Include="teapot.ico" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 61d58c9

Please sign in to comment.