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";
354 std::lock_guard<std::mutex> locker(
m_mutex);
357 std::string fnUtf8, anUtf8;
360 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
362 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), fnUtf8.data(), n,
nullptr,
nullptr);
365 const std::wstring& wAnim = animsMap[curAnimation.
animID];
368 int n = WideCharToMultiByte(CP_UTF8, 0, wAnim.c_str(),
static_cast<int>(wAnim.size()),
nullptr, 0,
nullptr,
nullptr);
370 WideCharToMultiByte(CP_UTF8, 0, wAnim.c_str(),
static_cast<int>(wAnim.size()), anUtf8.data(), n,
nullptr,
nullptr);
392 auto sp = mn.rfind(
'/');
393 if (sp != std::string::npos)
394 mn = mn.substr(sp + 1);
395 FbxString mtrl_name = mn.c_str();
396 mtrl_name.Append(
"_", 1);
398 _itoa(
static_cast<int>(i), tmp, 10);
399 mtrl_name.Append(tmp, strlen(tmp));
402 FbxString shading_name =
"Phong";
403 FbxSurfacePhong* material = FbxSurfacePhong::Create(
m_p_manager, mtrl_name.Buffer());
404 material->Ambient.Set(FbxDouble3(0.7, 0.7, 0.7));
408 std::string tex_name = tex;
409 auto slashPos = tex_name.rfind(
'/');
410 if (slashPos != std::string::npos)
411 tex_name = tex_name.substr(slashPos + 1);
412 if (
auto blpPos = tex_name.find(
".blp"); blpPos != std::string::npos)
413 tex_name.replace(blpPos, 4,
".png");
415 std::string filenameNarrow;
418 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
419 filenameNarrow.resize(n);
420 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), filenameNarrow.data(), n,
nullptr,
nullptr);
422 std::string tex_fullpath = filenameNarrow;
423 auto bsPos = tex_fullpath.rfind(
'\\');
424 if (bsPos != std::string::npos)
425 tex_fullpath = tex_fullpath.substr(0, bsPos + 1) + tex_name;
429 FbxFileTexture* texture = FbxFileTexture::Create(
m_p_manager, tex_name.c_str());
430 texture->SetFileName(tex_fullpath.c_str());
431 texture->SetTextureUse(FbxTexture::eStandard);
432 texture->SetMappingType(FbxTexture::eUV);
433 texture->SetMaterialUse(FbxFileTexture::eModelMaterial);
434 texture->SetSwapUV(
false);
435 texture->SetTranslation(0.0, 0.0);
436 texture->SetScale(1.0, 1.0);
437 texture->SetRotation(0.0, 0.0);
438 texture->UVSet.Set(FbxString(
"DiffuseUV"));
439 material->Diffuse.ConnectSrcObject(texture);
448 std::map<POSITION_SLOTS, WoWModel*> itemModels = it->models();
449 if (!itemModels.empty())
451 for (
const auto& itemModel : itemModels)
454 for (
unsigned int i = 0; i < model->
passes.size(); i++)
460 std::string mn2 = model->
name();
461 auto sp2 = mn2.rfind(
'/');
462 if (sp2 != std::string::npos)
463 mn2 = mn2.substr(sp2 + 1);
464 FbxString mtrl_name = mn2.c_str();
465 mtrl_name.Append(
"_", 1);
467 _itoa(
static_cast<int>(i), tmp, 10);
468 mtrl_name.Append(tmp, strlen(tmp));
471 FbxString shading_name =
"Phong";
472 FbxSurfacePhong* material = FbxSurfacePhong::Create(
m_p_manager, mtrl_name.Buffer());
473 material->Ambient.Set(FbxDouble3(0.7, 0.7, 0.7));
477 std::string tex_name = tex;
478 auto slashPos2 = tex_name.rfind(
'/');
479 if (slashPos2 != std::string::npos)
480 tex_name = tex_name.substr(slashPos2 + 1);
481 if (
auto blpPos = tex_name.find(
".blp"); blpPos != std::string::npos)
482 tex_name.replace(blpPos, 4,
".png");
484 std::string filenameNarrow2;
487 int n = WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()),
nullptr, 0,
nullptr,
nullptr);
488 filenameNarrow2.resize(n);
489 WideCharToMultiByte(CP_UTF8, 0,
m_filename.c_str(),
static_cast<int>(
m_filename.size()), filenameNarrow2.data(), n,
nullptr,
nullptr);
491 std::string tex_fullpath2 = filenameNarrow2;
492 auto bsPos2 = tex_fullpath2.rfind(
'\\');
493 if (bsPos2 != std::string::npos)
494 tex_fullpath2 = tex_fullpath2.substr(0, bsPos2 + 1) + tex_name;
498 FbxFileTexture* texture = FbxFileTexture::Create(
m_p_manager, tex_name.c_str());
499 texture->SetFileName(tex_fullpath2.c_str());
500 texture->SetTextureUse(FbxTexture::eStandard);
501 texture->SetMappingType(FbxTexture::eUV);
502 texture->SetMaterialUse(FbxFileTexture::eModelMaterial);
503 texture->SetSwapUV(
false);
504 texture->SetTranslation(0.0, 0.0);
505 texture->SetScale(1.0, 1.0);
506 texture->SetRotation(0.0, 0.0);
507 texture->UVSet.Set(FbxString(
"DiffuseUV"));
508 material->Diffuse.ConnectSrcObject(texture);