Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Asset export #538

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dev/Code/Sandbox/Editor/Export/ExportManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "Util/AutoDirectoryRestoreFileDialog.h"
#include "QtUI/WaitCursor.h"
#include "Maestro/Types/AnimParamType.h"
#include "Material/MaterialManager.h"

#include "QtUtil.h"

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion dev/Code/Sandbox/Editor/Export/ExportManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions dev/Code/Sandbox/Editor/Util/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "Util/PathUtil.h"
#include "AutoDirectoryRestoreFileDialog.h"
#include "MainWindow.h"
#include "Export/ExportManager.h"

#include <AzCore/PlatformIncl.h>
#include <AzCore/Component/TickBus.h>
Expand Down Expand Up @@ -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<CExportManager*>(GetIEditor()->GetExportManager());
if (exportMgr)
{
QString relativeGamePath = Path::MakeGamePath(fullGamePath);
relativeGamePath = Path::AddSlash(relativeGamePath) + filename;
constexpr bool useStreaming = false;
_smart_ptr<IStatObj> 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;
Expand Down