mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-20 19:57:44 +00:00
Add model export support
This commit is contained in:
parent
bef13de12f
commit
4a1d0cb0a1
4 changed files with 61 additions and 3 deletions
|
@ -31,7 +31,7 @@ else()
|
|||
endif()
|
||||
|
||||
# macos
|
||||
if(UNIX AND NOT LINUX)
|
||||
if(APPLE)
|
||||
set(USE_STANDALONE_WINDOW TRUE)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
find_package(assimp REQUIRED)
|
||||
|
||||
add_executable(mdlviewer
|
||||
src/main.cpp
|
||||
src/mainwindow.cpp)
|
||||
target_include_directories(mdlviewer
|
||||
PUBLIC
|
||||
include)
|
||||
target_link_libraries(mdlviewer PUBLIC libxiv ${LIBRARIES} Qt5::Core Qt5::Widgets renderer)
|
||||
target_link_libraries(mdlviewer PUBLIC
|
||||
libxiv
|
||||
${LIBRARIES}
|
||||
Qt5::Core
|
||||
Qt5::Widgets
|
||||
renderer
|
||||
assimp::assimp)
|
||||
|
||||
install(TARGETS mdlviewer
|
||||
DESTINATION "${INSTALL_BIN_PATH}")
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
|
||||
void refreshModel();
|
||||
|
||||
void exportModel(Model& model);
|
||||
|
||||
private:
|
||||
std::vector<GearInfo> gears;
|
||||
std::vector<GearInfo*> loadedGears;
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include <QResizeEvent>
|
||||
#include <QComboBox>
|
||||
#include <QTimer>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
#include "gamedata.h"
|
||||
#include "exhparser.h"
|
||||
|
@ -198,3 +201,48 @@ void MainWindow::refreshModel() {
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::exportModel(Model& model) {
|
||||
Assimp::Exporter exporter;
|
||||
|
||||
aiScene scene;
|
||||
scene.mRootNode = new aiNode();
|
||||
|
||||
scene.mNumMaterials = 1;
|
||||
scene.mMaterials = new aiMaterial*[1];
|
||||
scene.mMaterials[0] = new aiMaterial();
|
||||
|
||||
scene.mNumMeshes = 1;
|
||||
scene.mMeshes = new aiMesh*[scene.mNumMeshes];
|
||||
scene.mMeshes[0] = new aiMesh();
|
||||
scene.mMeshes[0]->mMaterialIndex = 0;
|
||||
|
||||
scene.mRootNode->mNumMeshes = 1;
|
||||
scene.mRootNode->mMeshes = new unsigned int [scene.mRootNode->mNumMeshes];
|
||||
scene.mRootNode->mMeshes[0] = 0;
|
||||
|
||||
auto mesh = scene.mMeshes[0];
|
||||
mesh->mNumVertices = model.lods[0].parts[0].vertices.size();
|
||||
mesh->mVertices = new aiVector3D [mesh->mNumVertices];
|
||||
for(int i = 0; i < mesh->mNumVertices; i++) {
|
||||
auto vertex = model.lods[0].parts[0].vertices[i];
|
||||
mesh->mVertices[i] = aiVector3D(vertex.position[0], vertex.position[1], vertex.position[2]);
|
||||
}
|
||||
|
||||
mesh->mNumFaces = model.lods[0].parts[0].indices.size() / 3;
|
||||
mesh->mFaces = new aiFace[mesh->mNumFaces];
|
||||
|
||||
int lastFace = 0;
|
||||
for(int i = 0; i < model.lods[0].parts[0].indices.size(); i += 3) {
|
||||
aiFace& face = mesh->mFaces[lastFace++];
|
||||
|
||||
face.mNumIndices = 3;
|
||||
face.mIndices = new unsigned int[face.mNumIndices];
|
||||
|
||||
face.mIndices[0] = model.lods[0].parts[0].indices[i];
|
||||
face.mIndices[1] = model.lods[0].parts[0].indices[i + 1];
|
||||
face.mIndices[2] = model.lods[0].parts[0].indices[i + 2];
|
||||
}
|
||||
|
||||
exporter.Export(&scene, "fbx", "test.fbx");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue