work toward a unicode-compatible max converter

This commit is contained in:
rdb 2013-10-07 22:36:05 +00:00
parent 146f56e01e
commit e1ff689adc
4 changed files with 141 additions and 110 deletions

View File

@ -470,23 +470,23 @@ void MaxEggPlugin::UpdateUI() {
LV_COLUMN pCol;
if (ListView_GetColumnWidth(lv, 1) <= 0 || ListView_GetColumnWidth(lv, 1) > 10000) {
//Columns have not been setup, so initialize the control
// Columns have not been setup, so initialize the control
ListView_SetExtendedListViewStyleEx(lv, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT,
LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
pCol.fmt = LVCFMT_LEFT;
pCol.cx = 96;
pCol.pszText = "Filename";
pCol.pszText = _T("Filename");
pCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
pCol.iSubItem = 0;
ListView_InsertColumn(lv, 0, &pCol);
pCol.cx = 44;
pCol.pszText = "Type";
pCol.pszText = _T("Type");
ListView_InsertColumn(lv, 1, &pCol);
}
//Add the eggs to the list
// Add the eggs to the list
ListView_DeleteAllItems(lv);
LV_ITEM Item;
Item.mask = LVIF_TEXT;
@ -498,11 +498,11 @@ void MaxEggPlugin::UpdateUI() {
ListView_InsertItem(lv, &Item);
Item.iSubItem = 1;
switch(eggList[i]->_anim_type) {
case MaxEggOptions::AT_chan: Item.pszText = "Animation"; break;
case MaxEggOptions::AT_both: Item.pszText = "Both"; break;
case MaxEggOptions::AT_pose: Item.pszText = "Static"; break;
case MaxEggOptions::AT_model: Item.pszText = "Model"; break;
default: Item.pszText = "Model"; break;
case MaxEggOptions::AT_chan: Item.pszText = _T("Animation"); break;
case MaxEggOptions::AT_both: Item.pszText = _T("Both"); break;
case MaxEggOptions::AT_pose: Item.pszText = _T("Static"); break;
case MaxEggOptions::AT_model: Item.pszText = _T("Model"); break;
default: Item.pszText = _T("Model"); break;
}
ListView_SetItem(lv, &Item);
ListView_SetCheckState(lv, i, eggList[i]->_checked);
@ -520,7 +520,7 @@ void MaxEggPlugin::UpdateUI() {
void MaxEggPlugin::DoExport() {
int good = 0, bad = 0;
std::stringstream status;
std::basic_stringstream<TCHAR> status;
SaveCheckState();
@ -530,22 +530,22 @@ void MaxEggPlugin::DoExport() {
// ask if the user wishes to overwrite the file
bool do_write = true;
if (!autoOverwrite && Filename::from_os_specific(eggList[i]->_file_name).exists()) {
char msg[1024];
sprintf(msg, "Overwrite file \"%s.egg\"?", eggList[i]->_short_name);
do_write = (MessageBox(hMaxEggParams, msg, "Panda3D Exporter", MB_YESNO | MB_ICONQUESTION) == IDYES);
TCHAR msg[1024];
_stprintf(msg, "Overwrite file \"%s.egg\"?", eggList[i]->_short_name);
do_write = (MessageBox(hMaxEggParams, msg, _T("Panda3D Exporter"), MB_YESNO | MB_ICONQUESTION) == IDYES);
}
if (do_write) {
MaxToEggConverter converter;
if (converter.convert((MaxEggOptions*)eggList[i])) {
good += 1;
status << "Successfully created " << eggList[i]->_short_name << ".egg\n";
status << _T("Successfully created ") << eggList[i]->_short_name << _T(".egg\n");
} else {
bad += 1;
status << "Could not export " << eggList[i]->_short_name << ".egg\n";
status << _T("Could not export ") << eggList[i]->_short_name << _T(".egg\n");
}
} else {
bad += 1;
status << "Skipped file " << eggList[i]->_short_name << ".egg\n";
status << _T("Skipped file ") << eggList[i]->_short_name << _T(".egg\n");
}
}
}
@ -554,11 +554,11 @@ void MaxEggPlugin::DoExport() {
if (good == 0 && bad == 0) {
mask |= MB_ICONEXCLAMATION;
MessageBox(hMaxEggParams, "Nothing to export!", "Panda3D Export results", mask);
MessageBox(hMaxEggParams, _T("Nothing to export!"), _T("Panda3D Export results"), mask);
} else {
if (bad > 0) mask |= MB_ICONEXCLAMATION;
else mask |= MB_ICONINFORMATION;
MessageBox(hMaxEggParams, status.str().c_str(), "Panda3D Export results", mask);
MessageBox(hMaxEggParams, status.str().c_str(), _T("Panda3D Export results"), mask);
}
int pviewed = 0;
@ -569,17 +569,17 @@ void MaxEggPlugin::DoExport() {
PROCESS_INFORMATION pi;
STARTUPINFO si;
memset(&si,0,sizeof(si));
si.cb= sizeof(si);
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
char cmdLine[2048];
TCHAR cmdLine[2048];
// If we have just one model and animation file, pview them both
if (numEggs == 2 && eggList[i]->_anim_type == MaxEggOptions::AT_model &&
eggList[1-i]->_checked && eggList[1-i]->_successful &&
eggList[1-i]->_anim_type == MaxEggOptions::AT_chan) {
sprintf(cmdLine, "pview \"%s\" \"%s\"", eggList[i]->_file_name, eggList[1-i]->_file_name);
_stprintf(cmdLine, _T("pview \"%s\" \"%s\""), eggList[i]->_file_name, eggList[1-i]->_file_name);
} else {
sprintf(cmdLine, "pview \"%s\"", eggList[i]->_file_name);
_stprintf(cmdLine, _T("pview \"%s\""), eggList[i]->_file_name);
}
CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,
NULL, NULL, &si, &pi);

View File

@ -15,7 +15,7 @@
//Disable the forcing int to true or false performance warning
#pragma warning(disable: 4800)
void SetICustEdit(HWND wnd, int nIDDlgItem, char *text)
void SetICustEdit(HWND wnd, int nIDDlgItem, const TCHAR *text)
{
ICustEdit *edit = GetICustEdit(GetDlgItem(wnd, nIDDlgItem));
edit->SetText(text);
@ -24,18 +24,18 @@ void SetICustEdit(HWND wnd, int nIDDlgItem, char *text)
void SetICustEdit(HWND wnd, int nIDDlgItem, int n)
{
char text[80];
sprintf(text, "%d", n);
TCHAR text[80];
_stprintf(text, _T("%d"), n);
ICustEdit *edit = GetICustEdit(GetDlgItem(wnd, nIDDlgItem));
edit->SetText(text);
ReleaseICustEdit(edit);
}
char *GetICustEditT(HWND wnd)
TCHAR *GetICustEditT(HWND wnd)
{
static char buffer[2084];
static TCHAR buffer[2084];
ICustEdit *edit = GetICustEdit(wnd);
edit->GetText(buffer,2084);
edit->GetText(buffer, 2084);
ReleaseICustEdit(edit);
return buffer;
}
@ -72,24 +72,24 @@ void ChunkSave(ISave *isave, int chunkid, bool value)
isave->EndChunk();
}
void ChunkSave(ISave *isave, int chunkid, char *value)
void ChunkSave(ISave *isave, int chunkid, TCHAR *value)
{
ULONG nb;
isave->BeginChunk(chunkid);
int bytes = strlen(value) + 1;
isave->Write(&bytes, sizeof(int), &nb);
isave->Write(value, bytes, &nb);
int length = _tcslen(value) + 1;
isave->Write(&length, sizeof(int), &nb);
isave->Write(value, length * sizeof(TCHAR), &nb);
isave->EndChunk();
}
char *ChunkLoadString(ILoad *iload, char *buffer, int maxBytes)
TCHAR *ChunkLoadString(ILoad *iload, TCHAR *buffer, int maxLength)
{
ULONG nb;
int bytes;
int length;
IOResult res;
res = iload->Read(&bytes, sizeof(int), &nb);
assert(res == IO_OK && bytes <= maxBytes);
res = iload->Read(buffer, bytes, &nb);
res = iload->Read(&length, sizeof(int), &nb);
assert(res == IO_OK && length <= maxLength);
res = iload->Read(buffer, length * sizeof(TCHAR), &nb);
assert(res == IO_OK);
return buffer;
}
@ -128,7 +128,7 @@ void showAnimControls(HWND hWnd, BOOL val) {
ShowWindow(GetDlgItem(hWnd, IDC_EF), val);
ShowWindow(GetDlgItem(hWnd, IDC_SF_LABEL), val);
SetWindowText(GetDlgItem(hWnd, IDC_EXP_SEL_FRAMES),
val ? "Use Range:" : "Use Frame:");
val ? _T("Use Range:") : _T("Use Frame:"));
}
void enableAnimControls(HWND hWnd, BOOL val) {
@ -262,7 +262,7 @@ MaxEggOptions::MaxEggOptions() {
INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
char tempFilename[2048];
TCHAR tempFilename[2048];
//We pass in our plugin through the lParam variable. Let's convert it back.
MaxOptionsDialog *imp = (MaxOptionsDialog*)GetWindowLongPtr(hWnd,GWLP_USERDATA);
if ( !imp && message != WM_INITDIALOG ) return FALSE;
@ -286,7 +286,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_MODEL:
if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Meshes:");
_T("Export Meshes:"));
enableAnimRadios(hWnd, ANIM_RAD_NONE);
showAnimControls(hWnd, TRUE);
enableAnimControls(hWnd, FALSE);
@ -300,7 +300,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_ANIMATION:
if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Bones:");
_T("Export Bones:"));
enableAnimRadios(hWnd, ANIM_RAD_ALL);
showAnimControls(hWnd, TRUE);
enableAnimControls(hWnd, IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES));
@ -314,7 +314,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_BOTH:
if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Models:");
_T("Export Models:"));
enableAnimRadios(hWnd, ANIM_RAD_ALL);
showAnimControls(hWnd, TRUE);
enableAnimControls(hWnd, IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES));
@ -328,7 +328,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_POSE:
if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Meshes:");
_T("Export Meshes:"));
enableAnimRadios(hWnd, ANIM_RAD_EXPSEL);
showAnimControls(hWnd, FALSE);
enableAnimControls(hWnd, TRUE);
@ -415,7 +415,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
return TRUE; break;
case IDC_BROWSE:
OPENFILENAME ofn;
strcpy(tempFilename, GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME)));
_tcscpy(tempFilename, GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME)));
memset(&ofn, 0, sizeof(ofn));
ofn.nMaxFile = 2047;
@ -423,8 +423,8 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST;
ofn.lpstrDefExt = "egg";
ofn.lpstrFilter = "Panda3D Egg Files (*.egg)\0*.egg\0All Files (*.*)\0*.*\0";
ofn.lpstrDefExt = _T("egg");
ofn.lpstrFilter = _T("Panda3D Egg Files (*.egg)\0*.egg\0All Files (*.*)\0*.*\0");
SetFocus(GetDlgItem(hWnd, IDC_FILENAME));
if (GetSaveFileName(&ofn))
@ -437,9 +437,9 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
return TRUE; break;
case IDC_CHECK1:
if (IsDlgButtonChecked(hWnd, IDC_CHECK1))
if (MessageBox(hWnd, "Warning: Exporting double-sided polygons can severely hurt "
"performance in Panda3D.\n\nAre you sure you want to export them?",
"Panda3D Exporter", MB_YESNO | MB_ICONQUESTION) != IDYES)
if (MessageBox(hWnd, _T("Warning: Exporting double-sided polygons can severely hurt ")
_T("performance in Panda3D.\n\nAre you sure you want to export them?"),
_T("Panda3D Exporter"), MB_YESNO | MB_ICONQUESTION) != IDYES)
CheckDlgButton(hWnd, IDC_CHECK1, BST_UNCHECKED);
return TRUE; break;
@ -533,7 +533,7 @@ bool MaxOptionsDialog::UpdateFromUI(HWND hWnd) {
BOOL valid;
Anim_Type newAnimType;
int newSF = INT_MIN, newEF = INT_MIN;
char msg[1024];
TCHAR msg[1024];
if (IsDlgButtonChecked(hWnd, IDC_MODEL)) newAnimType = MaxEggOptions::AT_model;
else if (IsDlgButtonChecked(hWnd, IDC_ANIMATION)) newAnimType = MaxEggOptions::AT_chan;
@ -543,56 +543,58 @@ bool MaxOptionsDialog::UpdateFromUI(HWND hWnd) {
if (newAnimType != MaxEggOptions::AT_model && IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES)) {
newSF = GetICustEditI(GetDlgItem(hWnd, IDC_SF), &valid);
if (!valid) {
MessageBox(hWnd, "Start Frame must be an integer", "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
MessageBox(hWnd, _T("Start Frame must be an integer"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (newSF < _min_frame) {
sprintf(msg, "Start Frame must be at least %d", _min_frame);
MessageBox(hWnd, msg, "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
_stprintf(msg, _T("Start Frame must be at least %d"), _min_frame);
MessageBox(hWnd, msg, _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (newSF > _max_frame) {
sprintf(msg, "Start Frame must be at most %d", _max_frame);
MessageBox(hWnd, msg, "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
_stprintf(msg, _T("Start Frame must be at most %d"), _max_frame);
MessageBox(hWnd, msg, _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (newAnimType != MaxEggOptions::AT_pose) {
newEF = GetICustEditI(GetDlgItem(hWnd, IDC_EF), &valid);
if (!valid) {
MessageBox(hWnd, "End Frame must be an integer", "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
MessageBox(hWnd, _T("End Frame must be an integer"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (newEF > _max_frame) {
sprintf(msg, "End Frame must be at most %d", _max_frame);
MessageBox(hWnd, msg, "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
_stprintf(msg, _T("End Frame must be at most %d"), _max_frame);
MessageBox(hWnd, msg, _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (newEF < newSF) {
MessageBox(hWnd, "End Frame must be greater than the start frame", "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
MessageBox(hWnd, _T("End Frame must be greater than the start frame"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
}
}
char *temp = GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME));
if (!strlen(temp)) {
MessageBox(hWnd, "The filename cannot be empty", "Invalid Value", MB_OK | MB_ICONEXCLAMATION);
TCHAR *temp = GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME));
if (!_tcslen(temp)) {
MessageBox(hWnd, _T("The filename cannot be empty"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (strlen(temp) < 4 || strncmp(".egg", temp+(strlen(temp) - 4), 4))
sprintf(_file_name, "%s.egg", temp);
else strcpy(_file_name, temp);
if (_tcslen(temp) < 4 || _tcsncmp(_T(".egg"), temp+(_tcslen(temp) - 4), 4)) {
_stprintf(_file_name, _T("%s.egg"), temp);
} else {
_tcscpy(_file_name, temp);
}
temp = strrchr(_file_name, '\\');
temp = _tcsrchr(_file_name, '\\');
if (!temp) temp = _file_name;
else temp++;
if (strlen(temp) > sizeof(_short_name))
sprintf(_short_name, "%.*s...", sizeof(_short_name)-4, temp);
if (_tcslen(temp) > sizeof(_short_name))
_stprintf(_short_name, _T("%.*s..."), sizeof(_short_name)-4, temp);
else {
strcpy(_short_name, temp);
_short_name[strlen(_short_name) - 4] = NULL; //Cut off the .egg
_tcscpy(_short_name, temp);
_short_name[_tcslen(_short_name) - 4] = NULL; //Cut off the .egg
}
_start_frame = newSF;

View File

@ -42,11 +42,11 @@ extern HINSTANCE hInstance;
void ChunkSave(ISave *isave, int chunkid, int value);
void ChunkSave(ISave *isave, int chunkid, bool value);
void ChunkSave(ISave *isave, int chunkid, char *value);
char *ChunkLoadString(ILoad *iload, char *buffer, int maxBytes);
TCHAR *ChunkLoadString(ILoad *iload, TCHAR *buffer, int maxLength);
int ChunkLoadInt(ILoad *iload);
bool ChunkLoadBool(ILoad *iload);
void SetICustEdit(HWND wnd, int nIDDlgItem, char *text);
INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message,
void SetICustEdit(HWND wnd, int nIDDlgItem, TCHAR *text);
INT_PTR CALLBACK MaxOptionsDialogProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam );
struct MaxEggOptions
@ -71,8 +71,8 @@ struct MaxEggOptions
bool _successful;
bool _export_whole_scene;
bool _export_all_frames;
char _file_name[2048];
char _short_name[256];
TCHAR _file_name[2048];
TCHAR _short_name[256];
PT(PathReplace) _path_replace;
std::vector<ULONG> _node_list;
};
@ -90,8 +90,8 @@ class MaxOptionsDialog : public MaxEggOptions
MaxOptionsDialog();
~MaxOptionsDialog();
//All these List functions should probably take what list they need to operate on
//rather than just operating on a global list
// All these List functions should probably take what list they need to operate on
// rather than just operating on a global list
void SetMaxInterface(IObjParam *iface) { _max_interface = iface; }
void UpdateUI(HWND hWnd);
bool UpdateFromUI(HWND hWnd);

View File

@ -71,7 +71,13 @@ bool MaxToEggConverter::convert(MaxEggOptions *options) {
_options = options;
Filename fn = Filename::from_os_specific(_options->_file_name);
Filename fn;
#ifdef _UNICODE
fn = Filename::from_os_specific_w(_options->_file_name);
#else
fn = Filename::from_os_specific(_options->_file_name);
#endif
_options->_path_replace->_path_directory = fn.get_dirname();
_egg_data = new EggData;
@ -163,7 +169,11 @@ bool MaxToEggConverter::convert(MaxEggOptions *options) {
_options->_successful = all_ok;
if (all_ok) {
#ifdef _UNICODE
Filename fn = Filename::from_os_specific_w(_options->_file_name);
#else
Filename fn = Filename::from_os_specific(_options->_file_name);
#endif
return _egg_data->write_egg(fn);
} else {
return false;
@ -1016,7 +1026,6 @@ get_panda_material(Mtl *mtl, MtlID matID) {
pandaMat._color[2] = diffuseColor.z;
}
if (!pandaMat._any_opacity) {
pandaMat._color[3] = (maxMaterial->GetOpacity(_current_frame * GetTicksPerFrame()));
}
if (pandaMat._texture_list.size() < 1) {
@ -1053,7 +1062,11 @@ void MaxToEggConverter::analyze_diffuse_maps(PandaMaterial &pandaMat, Texmap *ma
BitmapTex *diffuseTex = (BitmapTex *)mat;
Filename fullpath, outpath;
#ifdef _UNICDOE
Filename filename = Filename::from_os_specific_w(diffuseTex->GetMapName());
#else
Filename filename = Filename::from_os_specific(diffuseTex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath);
tex->set_filename(outpath);
@ -1094,7 +1107,11 @@ void MaxToEggConverter::analyze_opacity_maps(PandaMaterial &pandaMat, Texmap *ma
BitmapTex *transTex = (BitmapTex *)mat;
Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(transTex->GetMapName());
#else
Filename filename = Filename::from_os_specific(transTex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath);
@ -1146,7 +1163,11 @@ void MaxToEggConverter::analyze_glow_maps(PandaMaterial &pandaMat, Texmap *mat)
BitmapTex *gtex = (BitmapTex *)mat;
Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(gtex->GetMapName());
#else
Filename filename = Filename::from_os_specific(gtex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath);
@ -1191,7 +1212,11 @@ void MaxToEggConverter::analyze_gloss_maps(PandaMaterial &pandaMat, Texmap *mat)
BitmapTex *gtex = (BitmapTex *)mat;
Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(gtex->GetMapName());
#else
Filename filename = Filename::from_os_specific(gtex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath);
@ -1236,7 +1261,11 @@ void MaxToEggConverter::analyze_normal_maps(PandaMaterial &pandaMat, Texmap *mat
BitmapTex *ntex = (BitmapTex *)mat;
Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(ntex->GetMapName());
#else
Filename filename = Filename::from_os_specific(ntex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath);