diff --git a/dev/Code/Sandbox/Editor/Export/ExportManager.cpp b/dev/Code/Sandbox/Editor/Export/ExportManager.cpp index 28f35d105c..3b1e4298d6 100644 --- a/dev/Code/Sandbox/Editor/Export/ExportManager.cpp +++ b/dev/Code/Sandbox/Editor/Export/ExportManager.cpp @@ -40,6 +40,7 @@ #include "Util/AutoDirectoryRestoreFileDialog.h" #include "QtUI/WaitCursor.h" #include "Maestro/Types/AnimParamType.h" +#include "Material/MaterialManager.h" #include "QtUtil.h" @@ -2079,9 +2080,27 @@ bool CExportManager::ImportFromFile(const char* filename) bool CExportManager::ExportSingleStatObj(IStatObj* pStatObj, const char* filename) { Export::CObject* pObj = new Export::CObject(Path::GetFileName(filename).toUtf8().data()); + + // the exporter uses m_pBaseObj to find the material and submesh settings + // so we create a temporary brush editor object and set the material we want to use + CBaseObjectPtr editorObject = GetIEditor()->NewObject("Brush", "", "TempExportObject", 0.f, 0.f, 0.f, false); + if (editorObject) + { + auto material = pStatObj->GetMaterial(); + CMaterial* editorMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(material->GetName()); + editorObject->SetMaterial(editorMaterial); + m_pBaseObj = editorObject; + } AddStatObj(pObj, pStatObj); m_data.m_objects.push_back(pObj); ExportToFile(filename, true); + + if (editorObject) + { + m_pBaseObj = nullptr; + GetIEditor()->DeleteObject(editorObject); + } + return true; } diff --git a/dev/Code/Sandbox/Editor/Export/ExportManager.h b/dev/Code/Sandbox/Editor/Export/ExportManager.h index 04755ac287..3034699e9b 100644 --- a/dev/Code/Sandbox/Editor/Export/ExportManager.h +++ b/dev/Code/Sandbox/Editor/Export/ExportManager.h @@ -192,7 +192,7 @@ class CExportManager TExporters m_exporters; Export::CData m_data; bool m_isPrecaching; - bool m_isOccluder; + bool m_isOccluder = false; // if true, export lower resolution LOD if available float m_fScale; TObjectMap m_objectMap; bool m_bAnimationExport; diff --git a/dev/Code/Sandbox/Editor/Util/FileUtil.cpp b/dev/Code/Sandbox/Editor/Util/FileUtil.cpp index 22abcc53e3..82cc0a984f 100644 --- a/dev/Code/Sandbox/Editor/Util/FileUtil.cpp +++ b/dev/Code/Sandbox/Editor/Util/FileUtil.cpp @@ -43,6 +43,7 @@ #include "Util/PathUtil.h" #include "AutoDirectoryRestoreFileDialog.h" #include "MainWindow.h" +#include "Export/ExportManager.h" #include #include @@ -2021,6 +2022,35 @@ void CFileUtil::PopulateQMenu(QWidget* caller, QMenu* menu, const QString& filen action = menu->addAction(QObject::tr("Copy Path To Clipboard"), [fullPath]() { QApplication::clipboard()->setText(fullPath); }); + if (!filename.isEmpty() && filename.endsWith(".cgf", Qt::CaseInsensitive)) + { + action = menu->addAction(QObject::tr("Export"), [=]() + { + QFileInfo fi(fullPath); + QString fileDirPath = fi.absolutePath(); + QString saveFilePath = QFileDialog::getSaveFileName( + NULL, + QFileDialog::tr("Export Geometry"), + fileDirPath, + QFileDialog::tr("Object File (*.obj);;FBX File (*.fbx)")); + + if (saveFilePath.isEmpty()) + { + return; + } + + CExportManager* exportMgr = static_cast(GetIEditor()->GetExportManager()); + if (exportMgr) + { + QString relativeGamePath = Path::MakeGamePath(fullGamePath); + relativeGamePath = Path::AddSlash(relativeGamePath) + filename; + constexpr bool useStreaming = false; + _smart_ptr statObj = GetIEditor()->Get3DEngine()->LoadStatObjAutoRef(relativeGamePath.toStdString().c_str(),nullptr, nullptr, useStreaming); + exportMgr->ExportSingleStatObj(statObj, saveFilePath.toStdString().c_str()); + } + }); + } + if (!filename.isEmpty() && GetIEditor()->IsSourceControlAvailable() && nFileAttr != SCC_FILE_ATTRIBUTE_INVALID) { bool isEnableSC = nFileAttr & SCC_FILE_ATTRIBUTE_MANAGED;