diff --git a/src/dialog.cpp b/src/dialog.cpp index 584fcaf..3edc8f4 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -92,6 +92,7 @@ SettingsDialog::SettingsDialog(IGUIEnvironment *env, IGUIElement *parent, IGUITab *tab_general = tabs->addTab(L"General"); IGUITab *tab_debug = tabs->addTab(L"Debug"); + IGUITab *tab_export = tabs->addTab(L"Export"); IGUISpinBox *spin; IGUICheckBox *check; ColorCtrl *color; @@ -145,6 +146,29 @@ SettingsDialog::SettingsDialog(IGUIEnvironment *env, IGUIElement *parent, E_DIALOG_ID_DEBUG_BUFFERS, L"Show all mesh buffers"); check->setChecked(conf->getInt("debug_flags") & EDS_BBOX_BUFFERS); + check = env->addCheckBox(false, rect(20,20,380,40), tab_export, + E_DIALOG_ID_EXPORT_ANIM, L"Apply animation pose"); + check->setChecked(conf->getInt("export_flags") & E_MESH_EXPORT_ANIM); + check = env->addCheckBox(false, rect(20,50,380,70), tab_export, + E_DIALOG_ID_EXPORT_TRANSFORM, L"Apply viewer transformations"); + check->setChecked(conf->getInt("export_flags") & E_MESH_EXPORT_TRANSFORM); + check = env->addCheckBox(false, rect(20,80,380,100), tab_export, + E_DIALOG_ID_EXPORT_FLIP, L"Flip Surfaces"); + check->setChecked(conf->getInt("export_flags") & E_MESH_EXPORT_FLIP); + check = env->addCheckBox(false, rect(20,110,380,130), tab_export, + E_DIALOG_ID_EXPORT_NORMAL, L"Recalculate normals"); + check->setChecked(conf->getInt("export_flags") & E_MESH_EXPORT_NORMAL); + + env->addStaticText(L"Scale:", rect(20,140,80,160), + false, false, tab_export); + env->addStaticText(L"%", rect(80,140,100,160), + false, false, tab_export); + spin = env->addSpinBox(L"", rect(100,140,180,160), false, tab_export, + E_DIALOG_ID_EXPORT_SCALE); + spin->setRange(0, 100); + spin->setValue(conf->getInt("export_scale")); + spin->setDecimalPlaces(0); + env->addButton(rect(315,255,395,285), this, E_DIALOG_ID_SETTINGS_OK, L"OK"); env->addButton(rect(230,255,310,285), this, @@ -212,6 +236,22 @@ bool SettingsDialog::OnEvent(const SEvent &event) if (isBoxChecked(E_DIALOG_ID_DEBUG_BUFFERS)) flags |= EDS_BBOX_BUFFERS; conf->set("debug_flags", std::to_string(flags)); + + flags = 0; + if (isBoxChecked(E_DIALOG_ID_EXPORT_ANIM)) + flags |= E_MESH_EXPORT_ANIM; + if (isBoxChecked(E_DIALOG_ID_EXPORT_TRANSFORM)) + flags |= E_MESH_EXPORT_TRANSFORM; + if (isBoxChecked(E_DIALOG_ID_EXPORT_FLIP)) + flags |= E_MESH_EXPORT_FLIP; + if (isBoxChecked(E_DIALOG_ID_EXPORT_NORMAL)) + flags |= E_MESH_EXPORT_NORMAL; + conf->set("export_flags", std::to_string(flags)); + + spin = (IGUISpinBox*) + getElementFromId(E_DIALOG_ID_EXPORT_SCALE, true); + u32 scale = spin->getValue(); + conf->set("export_scale", std::to_string(scale)); } return IGUIElement::OnEvent(event); } @@ -561,4 +601,4 @@ bool LightsDialog::OnEvent(const SEvent &event) } } return IGUIElement::OnEvent(event); -} +} \ No newline at end of file diff --git a/src/dialog.h b/src/dialog.h index f41492a..1cb6584 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -22,6 +22,12 @@ enum E_DIALOG_ID_DEBUG_WIREFRANE, E_DIALOG_ID_DEBUG_ALPHA, E_DIALOG_ID_DEBUG_BUFFERS, + E_DIALOG_ID_EXPORT_ANIM, + E_DIALOG_ID_EXPORT_TRANSFORM, + E_DIALOG_ID_EXPORT_FLIP, + E_DIALOG_ID_EXPORT_NORMAL, + E_DIALOG_ID_EXPORT_COMBINE, + E_DIALOG_ID_EXPORT_SCALE, E_DIALOG_ID_ABOUT_OK, E_DIALOG_ID_ABOUT_LINK, E_DIALOG_ID_SETTINGS_OK, @@ -53,6 +59,14 @@ enum E_DIALOG_ID_LIGHT_RADIUS = 0x2100 }; +enum +{ + E_MESH_EXPORT_ANIM = 1, + E_MESH_EXPORT_TRANSFORM = 2, + E_MESH_EXPORT_FLIP = 4, + E_MESH_EXPORT_NORMAL = 8 +}; + namespace dialog { static const int model_filter_count = 19; diff --git a/src/main.cpp b/src/main.cpp index 6e4776f..1c20505 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,6 +74,8 @@ int main() {"screen_height","600"}, {"debug_info", "false"}, {"debug_flags", "1"}, + {"export_flags", "1"}, + {"export_scale", "100"} }; conf->load(); for (std::map::iterator it = defaults.begin(); diff --git a/src/viewer.cpp b/src/viewer.cpp index 20ea2d6..16fb4dd 100644 --- a/src/viewer.cpp +++ b/src/viewer.cpp @@ -141,12 +141,47 @@ void Viewer::exportStaticMesh(const char *caption, const char **filters, if (!fn || stringc(fn).empty()) return; + u32 flags = conf->getInt("export_flags"); + u32 scale = conf->getInt("export_scale"); + IAnimatedMeshSceneNode *clone = 0; IAnimatedMeshSceneNode *model = (IAnimatedMeshSceneNode*)scene->getNode(E_SCENE_ID_MODEL); - IAnimatedMesh *mesh = model->getMesh(); - io::IWriteFile *file = fs->createAndWriteFile(fn); + ISceneManager *smgr = device->getSceneManager(); - IMeshWriter *writer = smgr->createMeshWriter(id); + IMesh *mesh = model->getMesh(); + io::IWriteFile *file; + IMeshWriter *writer; + + if (!(flags & E_MESH_EXPORT_ANIM)) + { + clone = (IAnimatedMeshSceneNode*)model->clone(); + mesh = clone->getMesh(); + } + file = fs->createAndWriteFile(fn); + writer = smgr->createMeshWriter(id); + writer->writeMesh(file, mesh); + writer->drop(); + file->drop(); + if (clone) + clone->remove(); + if (scale == 100 && (flags == 0 || flags == E_MESH_EXPORT_ANIM)) + return; + + IMeshManipulator *manip = smgr->getMeshManipulator(); + mesh = smgr->getMesh(fn); + if (flags & E_MESH_EXPORT_FLIP) + manip->flipSurfaces(mesh); + if (flags & E_MESH_EXPORT_NORMAL) + manip->recalculateNormals(mesh); + if (flags & E_MESH_EXPORT_TRANSFORM) + manip->transform(mesh, model->getRelativeTransformation()); + if (scale != 100) + { + f32 sf = (f32)scale / 100.f; + manip->scale(mesh, vector3df(sf, sf, sf)); + } + file = fs->createAndWriteFile(fn); + writer = smgr->createMeshWriter(id); writer->writeMesh(file, mesh); writer->drop(); file->drop();