75 LOG_ERROR <<
"Unable to create the FBX SDK manager";
79 FbxIOSettings* ios = FbxIOSettings::Create(
m_p_manager, IOSROOT);
83 ios->SetBoolProp(EXP_FBX_MATERIAL,
true);
84 ios->SetBoolProp(EXP_FBX_TEXTURE,
true);
85 ios->SetBoolProp(EXP_FBX_EMBEDDED,
true);
86 ios->SetBoolProp(EXP_FBX_SHAPE,
true);
87 ios->SetBoolProp(EXP_FBX_GOBO,
true);
88 ios->SetBoolProp(EXP_FBX_ANIMATION,
false);
89 ios->SetBoolProp(EXP_FBX_GLOBAL_SETTINGS,
true);
91 FbxExporter* exporter =
nullptr;
95 std::string filenameUtf8;
98 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
99 filenameUtf8.resize(n);
100 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), filenameUtf8.data(), n,
nullptr,
nullptr);
107 FbxDocumentInfo* sceneInfo = FbxDocumentInfo::Create(
m_p_manager,
"SceneInfo");
110 auto sp = modelName.rfind(
'/');
111 if (sp != std::string::npos)
112 modelName = modelName.substr(sp + 1);
113 sceneInfo->mTitle = modelName.c_str();
117 if (!appName.empty())
119 int n = WideCharToMultiByte(CP_UTF8, 0, appName.c_str(),
static_cast<int>(appName.size()),
nullptr, 0,
nullptr,
nullptr);
120 std::string s(n,
'\0');
121 WideCharToMultiByte(CP_UTF8, 0, appName.c_str(),
static_cast<int>(appName.size()), s.data(), n,
nullptr,
nullptr);
122 sceneInfo->mAuthor = s.c_str();
129 int n = WideCharToMultiByte(CP_UTF8, 0, appVer.c_str(),
static_cast<int>(appVer.size()),
nullptr, 0,
nullptr,
nullptr);
130 std::string s(n,
'\0');
131 WideCharToMultiByte(CP_UTF8, 0, appVer.c_str(),
static_cast<int>(appVer.size()), s.data(), n,
nullptr,
nullptr);
132 sceneInfo->mRevision = s.c_str();
142 LOG_INFO <<
"Meshes successfully created";
145 LOG_INFO <<
"Materials successfully created";
148 LOG_INFO <<
"Skeleton successfully created";
157 std::map<POSITION_SLOTS, WoWModel*> itemModels = it->models();
158 if (!itemModels.empty())
160 for (
const auto& itemModel : itemModels)
172 catch (
const std::exception& ex)
174 LOG_ERROR <<
"Error during export:" << ex.what();
180 LOG_ERROR <<
"Unable to export FBX scene";
183 LOG_INFO <<
"Model successfully created";
187 _wremove((it.first).c_str());
195 LOG_INFO <<
"Animations successfully created";
197 catch (
const std::exception& ex)
199 LOG_ERROR <<
"Error during bulk animation export:" << ex.what();
204 LOG_INFO <<
"FBX scene successfully exported";
364 std::lock_guard<std::mutex> locker(
m_mutex);
367 std::string fnUtf8, anUtf8;
370 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
372 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), fnUtf8.data(), n,
nullptr,
nullptr);
375 const std::wstring& wAnim = animsMap[curAnimation.
animID];
378 int n = WideCharToMultiByte(CP_UTF8, 0, wAnim.c_str(),
static_cast<int>(wAnim.size()),
nullptr, 0,
nullptr,
nullptr);
380 WideCharToMultiByte(CP_UTF8, 0, wAnim.c_str(),
static_cast<int>(wAnim.size()), anUtf8.data(), n,
nullptr,
nullptr);
403 auto sp = mn.rfind(
'/');
404 if (sp != std::string::npos)
405 mn = mn.substr(sp + 1);
406 FbxString mtrl_name = mn.c_str();
407 mtrl_name.Append(
"_", 1);
409 _itoa(
static_cast<int>(i), tmp, 10);
410 mtrl_name.Append(tmp, strlen(tmp));
413 FbxString shading_name =
"Phong";
414 FbxSurfacePhong* material = FbxSurfacePhong::Create(
m_p_manager, mtrl_name.Buffer());
415 material->Ambient.Set(FbxDouble3(0.7, 0.7, 0.7));
419 std::string tex_name = tex;
420 auto slashPos = tex_name.rfind(
'/');
421 if (slashPos != std::string::npos)
422 tex_name = tex_name.substr(slashPos + 1);
423 if (
auto blpPos = tex_name.find(
".blp"); blpPos != std::string::npos)
424 tex_name.replace(blpPos, 4,
".png");
426 std::string filenameNarrow;
429 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
430 filenameNarrow.resize(n);
431 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), filenameNarrow.data(), n,
nullptr,
nullptr);
433 std::string tex_fullpath = filenameNarrow;
434 auto bsPos = tex_fullpath.rfind(
'\\');
435 if (bsPos != std::string::npos)
436 tex_fullpath = tex_fullpath.substr(0, bsPos + 1) + tex_name;
440 FbxFileTexture* texture = FbxFileTexture::Create(
m_p_manager, tex_name.c_str());
441 texture->SetFileName(tex_fullpath.c_str());
442 texture->SetTextureUse(FbxTexture::eStandard);
443 texture->SetMappingType(FbxTexture::eUV);
444 texture->SetMaterialUse(FbxFileTexture::eModelMaterial);
445 texture->SetSwapUV(
false);
446 texture->SetTranslation(0.0, 0.0);
447 texture->SetScale(1.0, 1.0);
448 texture->SetRotation(0.0, 0.0);
449 texture->UVSet.Set(FbxString(
"DiffuseUV"));
450 material->Diffuse.ConnectSrcObject(texture);
459 std::map<POSITION_SLOTS, WoWModel*> itemModels = it->models();
460 if (!itemModels.empty())
462 for (
const auto& itemModel : itemModels)
465 for (
unsigned int i = 0; i < model->
passes.size(); i++)
471 std::string mn2 = model->
name();
472 auto sp2 = mn2.rfind(
'/');
473 if (sp2 != std::string::npos)
474 mn2 = mn2.substr(sp2 + 1);
475 FbxString mtrl_name = mn2.c_str();
476 mtrl_name.Append(
"_", 1);
478 _itoa(
static_cast<int>(i), tmp, 10);
479 mtrl_name.Append(tmp, strlen(tmp));
482 FbxString shading_name =
"Phong";
483 FbxSurfacePhong* material = FbxSurfacePhong::Create(
m_p_manager, mtrl_name.Buffer());
484 material->Ambient.Set(FbxDouble3(0.7, 0.7, 0.7));
488 std::string tex_name = tex;
489 auto slashPos2 = tex_name.rfind(
'/');
490 if (slashPos2 != std::string::npos)
491 tex_name = tex_name.substr(slashPos2 + 1);
492 if (
auto blpPos = tex_name.find(
".blp"); blpPos != std::string::npos)
493 tex_name.replace(blpPos, 4,
".png");
495 std::string filenameNarrow2;
498 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
499 filenameNarrow2.resize(n);
500 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), filenameNarrow2.data(), n,
nullptr,
nullptr);
502 std::string tex_fullpath2 = filenameNarrow2;
503 auto bsPos2 = tex_fullpath2.rfind(
'\\');
504 if (bsPos2 != std::string::npos)
505 tex_fullpath2 = tex_fullpath2.substr(0, bsPos2 + 1) + tex_name;
509 FbxFileTexture* texture = FbxFileTexture::Create(
m_p_manager, tex_name.c_str());
510 texture->SetFileName(tex_fullpath2.c_str());
511 texture->SetTextureUse(FbxTexture::eStandard);
512 texture->SetMappingType(FbxTexture::eUV);
513 texture->SetMaterialUse(FbxFileTexture::eModelMaterial);
514 texture->SetSwapUV(
false);
515 texture->SetTranslation(0.0, 0.0);
516 texture->SetScale(1.0, 1.0);
517 texture->SetRotation(0.0, 0.0);
518 texture->UVSet.Set(FbxString(
"DiffuseUV"));
519 material->Diffuse.ConnectSrcObject(texture);