1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-30 15:37:46 +00:00

Add export button and support for exporting all mesh parts

This commit is contained in:
Joshua Goins 2022-04-12 20:18:22 -04:00
parent 4a1d0cb0a1
commit de2b6f6307
4 changed files with 63 additions and 36 deletions

View file

@ -50,7 +50,7 @@ public:
void refreshModel(); void refreshModel();
void exportModel(Model& model); void exportModel(Model& model, QString fileName);
private: private:
std::vector<GearInfo> gears; std::vector<GearInfo> gears;

View file

@ -14,6 +14,8 @@
#include <assimp/Exporter.hpp> #include <assimp/Exporter.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <QPushButton>
#include <QFileDialog>
#include "gamedata.h" #include "gamedata.h"
#include "exhparser.h" #include "exhparser.h"
@ -157,6 +159,9 @@ MainWindow::MainWindow(GameData& data) : data(data) {
timer->start(1000); timer->start(1000);
#endif #endif
QHBoxLayout* controlLayout = new QHBoxLayout();
viewportLayout->addLayout(controlLayout);
QComboBox* raceCombo = new QComboBox(); QComboBox* raceCombo = new QComboBox();
for(auto [race, raceName] : raceNames) { for(auto [race, raceName] : raceNames) {
raceCombo->addItem(raceName.data()); raceCombo->addItem(raceName.data());
@ -167,7 +172,19 @@ MainWindow::MainWindow(GameData& data) : data(data) {
refreshModel(); refreshModel();
}); });
viewportLayout->addWidget(raceCombo); controlLayout->addWidget(raceCombo);
QPushButton* exportButton = new QPushButton("Export");
connect(exportButton, &QPushButton::clicked, [this] {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Model"),
"model.fbx",
tr("FBX Files (*.fbx)"));
exportModel(vkWindow->models[0].model, fileName);
});
controlLayout->addWidget(exportButton);
connect(listWidget, &QListWidget::itemClicked, [this](QListWidgetItem* item) { connect(listWidget, &QListWidget::itemClicked, [this](QListWidgetItem* item) {
for(auto& gear : gears) { for(auto& gear : gears) {
@ -202,47 +219,55 @@ void MainWindow::refreshModel() {
} }
} }
void MainWindow::exportModel(Model& model) { void MainWindow::exportModel(Model& model, QString fileName) {
Assimp::Exporter exporter; Assimp::Exporter exporter;
aiScene scene; aiScene scene;
scene.mRootNode = new aiNode(); scene.mRootNode = new aiNode();
scene.mNumMaterials = 1; scene.mRootNode->mNumChildren = model.lods[0].parts.size();
scene.mMaterials = new aiMaterial*[1]; scene.mRootNode->mChildren = new aiNode*[scene.mRootNode->mNumChildren];
scene.mMaterials[0] = new aiMaterial();
scene.mNumMeshes = 1; scene.mNumMeshes = model.lods[0].parts.size();
scene.mMeshes = new aiMesh*[scene.mNumMeshes]; scene.mMeshes = new aiMesh*[scene.mNumMeshes];
scene.mMeshes[0] = new aiMesh();
scene.mMeshes[0]->mMaterialIndex = 0;
scene.mRootNode->mNumMeshes = 1; for(int i = 0; i < model.lods[0].parts.size(); i++) {
scene.mRootNode->mMeshes = new unsigned int [scene.mRootNode->mNumMeshes]; scene.mMeshes[i] = new aiMesh();
scene.mRootNode->mMeshes[0] = 0; scene.mMeshes[i]->mMaterialIndex = 0;
auto mesh = scene.mMeshes[0]; auto& node = scene.mRootNode->mChildren[i];
mesh->mNumVertices = model.lods[0].parts[0].vertices.size(); node = new aiNode();
node->mNumMeshes = 1;
node->mMeshes = new unsigned int [scene.mRootNode->mNumMeshes];
node->mMeshes[0] = i;
auto mesh = scene.mMeshes[i];
mesh->mNumVertices = model.lods[0].parts[i].vertices.size();
mesh->mVertices = new aiVector3D [mesh->mNumVertices]; mesh->mVertices = new aiVector3D [mesh->mNumVertices];
for(int i = 0; i < mesh->mNumVertices; i++) { for(int j = 0; j < mesh->mNumVertices; j++) {
auto vertex = model.lods[0].parts[0].vertices[i]; auto vertex = model.lods[0].parts[i].vertices[j];
mesh->mVertices[i] = aiVector3D(vertex.position[0], vertex.position[1], vertex.position[2]); mesh->mVertices[j] = aiVector3D(vertex.position[0], vertex.position[1], vertex.position[2]);
} }
mesh->mNumFaces = model.lods[0].parts[0].indices.size() / 3; mesh->mNumFaces = model.lods[0].parts[i].indices.size() / 3;
mesh->mFaces = new aiFace[mesh->mNumFaces]; mesh->mFaces = new aiFace[mesh->mNumFaces];
int lastFace = 0; int lastFace = 0;
for(int i = 0; i < model.lods[0].parts[0].indices.size(); i += 3) { for(int j = 0; j < model.lods[0].parts[i].indices.size(); j += 3) {
aiFace& face = mesh->mFaces[lastFace++]; aiFace& face = mesh->mFaces[lastFace++];
face.mNumIndices = 3; face.mNumIndices = 3;
face.mIndices = new unsigned int[face.mNumIndices]; face.mIndices = new unsigned int[face.mNumIndices];
face.mIndices[0] = model.lods[0].parts[0].indices[i]; face.mIndices[0] = model.lods[0].parts[i].indices[j];
face.mIndices[1] = model.lods[0].parts[0].indices[i + 1]; face.mIndices[1] = model.lods[0].parts[i].indices[j + 1];
face.mIndices[2] = model.lods[0].parts[0].indices[i + 2]; face.mIndices[2] = model.lods[0].parts[i].indices[j + 2];
}
} }
exporter.Export(&scene, "fbx", "test.fbx"); scene.mNumMaterials = 1;
scene.mMaterials = new aiMaterial*[1];
scene.mMaterials[0] = new aiMaterial();
exporter.Export(&scene, "fbx", fileName.toStdString());
} }

View file

@ -14,6 +14,7 @@ struct RenderPart {
}; };
struct RenderModel { struct RenderModel {
Model model;
std::vector<RenderPart> parts; std::vector<RenderPart> parts;
}; };

View file

@ -510,6 +510,7 @@ uint32_t Renderer::findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags pro
RenderModel Renderer::addModel(const Model& model) { RenderModel Renderer::addModel(const Model& model) {
RenderModel renderModel; RenderModel renderModel;
renderModel.model = model;
for(auto part : model.lods[0].parts) { for(auto part : model.lods[0].parts) {
RenderPart renderPart; RenderPart renderPart;