diff options
| author | yum <yum.food.vr@gmail.com> | 2022-12-20 00:26:50 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2022-12-20 00:28:46 -0800 |
| commit | 8d225cfd66dfb60998b4eab43d8aa3b287375695 (patch) | |
| tree | a298f7799fcc80085d568996a837367f9d16fe55 /GUI | |
| parent | 4f3da107d4379f99ec7ade8be26bfcf908fb193f (diff) | |
GUI: Begin work generating animator
The GUI can now generate guid.map and animations.
Diffstat (limited to 'GUI')
| -rw-r--r-- | GUI/GUI/GUI/Frame.cpp | 83 | ||||
| -rw-r--r-- | GUI/GUI/GUI/Frame.h | 2 | ||||
| -rw-r--r-- | GUI/GUI/GUI/PythonWrapper.cpp | 65 | ||||
| -rw-r--r-- | GUI/GUI/GUI/PythonWrapper.h | 11 |
4 files changed, 149 insertions, 12 deletions
diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index d535f85..1645258 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -31,6 +31,7 @@ namespace { ID_UNITY_PANEL,
ID_UNITY_CONFIG_PANEL,
ID_UNITY_OUT,
+ ID_UNITY_ASSETS_FILE_PICKER,
ID_UNITY_ANIMATOR_FILE_PICKER,
ID_UNITY_PARAMETERS_FILE_PICKER,
ID_UNITY_MENU_FILE_PICKER,
@@ -281,6 +282,14 @@ Frame::Frame() {
auto* unity_config_panel_pairs = new wxPanel(unity_config_panel, ID_UNITY_CONFIG_PANEL_PAIRS);
{
+ auto* unity_assets_file_picker = new wxDirPickerCtrl(
+ unity_config_panel_pairs,
+ ID_UNITY_ASSETS_FILE_PICKER,
+ /*path=*/wxEmptyString,
+ /*message=*/"Unity Assets folder"
+ );
+ unity_assets_file_picker_ = unity_assets_file_picker;
+
auto* unity_animator_file_picker = new wxFilePickerCtrl(
unity_config_panel_pairs,
ID_UNITY_ANIMATOR_FILE_PICKER,
@@ -312,7 +321,7 @@ Frame::Frame() /*pos=*/wxDefaultPosition,
/*size=*/wxDefaultSize
);
- unity_parameters_file_picker_ = unity_parameters_file_picker;
+ unity_menu_file_picker_ = unity_menu_file_picker;
auto* unity_animator_generated_dir = new wxTextCtrl(unity_config_panel_pairs,
ID_UNITY_ANIMATOR_GENERATED_DIR,
@@ -339,6 +348,9 @@ Frame::Frame() auto* sizer = new wxFlexGridSizer(/*cols=*/2);
unity_config_panel_pairs->SetSizer(sizer);
+ sizer->Add(new wxStaticText(unity_config_panel_pairs, wxID_ANY, /*label=*/"Unity Assets folder:"));
+ sizer->Add(unity_assets_file_picker);
+
sizer->Add(new wxStaticText(unity_config_panel_pairs, wxID_ANY, /*label=*/"FX controller:"));
sizer->Add(unity_animator_file_picker);
@@ -477,7 +489,64 @@ void Frame::OnDumpMics(wxCommandEvent& event) transcribe_out_->AppendText(PythonWrapper::DumpMics());
}
-void Frame::OnGenerateFX(wxCommandEvent& event) {
+#define DEBUG
+
+void Frame::OnGenerateFX(wxCommandEvent& event)
+{
+ std::filesystem::path unity_assets_path = unity_assets_file_picker_->GetPath().ToStdString();
+#ifndef DEBUG
+ if (!std::filesystem::exists(unity_assets_path)) {
+ std::ostringstream oss;
+ oss << "Cannot generate FX layer: assets directory does not exist at " << unity_assets_path << std::endl;
+ wxLogError(oss.str().c_str());
+ return;
+ }
+#endif
+ std::filesystem::path unity_animator_path = unity_animator_file_picker_->GetPath().ToStdString();
+#ifndef DEBUG
+ if (!std::filesystem::exists(unity_animator_path)) {
+ std::ostringstream oss;
+ oss << "Cannot generate FX layer: animator does not exist at " << unity_animator_path << std::endl;
+ wxLogError(oss.str().c_str());
+ return;
+ }
+#endif
+ std::filesystem::path unity_parameters_path = unity_parameters_file_picker_->GetPath().ToStdString();
+#ifndef DEBUG
+ if (!std::filesystem::exists(unity_parameters_path)) {
+ std::ostringstream oss;
+ oss << "Cannot generate FX layer: parameters do not exist at " << unity_parameters_path << std::endl;
+ wxLogError(oss.str().c_str());
+ return;
+ }
+#endif
+ std::filesystem::path unity_menu_path = unity_menu_file_picker_->GetPath().ToStdString();
+#ifndef DEBUG
+ if (!std::filesystem::exists(unity_menu_path)) {
+ std::ostringstream oss;
+ oss << "Cannot generate FX layer: menu does not exist at " << unity_menu_path << std::endl;
+ wxLogError(oss.str().c_str());
+ return;
+ }
+#endif
+ std::string unity_animator_generated_dir = unity_animator_generated_dir_->GetLineText(0).ToStdString();
+ std::string unity_animator_generated_name = unity_animator_generated_name_->GetLineText(0).ToStdString();
+ std::string unity_parameters_generated_name = unity_parameters_generated_name_->GetLineText(0).ToStdString();
+ std::string unity_menu_generated_name = unity_menu_generated_name_->GetLineText(0).ToStdString();
+
+ std::string out;
+ if (!PythonWrapper::GenerateAnimator(
+ unity_assets_path.string(),
+ unity_animator_path.string(),
+ unity_parameters_path.string(),
+ unity_menu_path.string(),
+ unity_animator_generated_dir,
+ unity_animator_generated_name,
+ unity_parameters_generated_name,
+ unity_menu_generated_name,
+ unity_out_)) {
+ wxLogError("Failed to generate animator:\n%s\n", out.c_str());
+ }
}
void Frame::OnAppStart(wxCommandEvent& event) {
@@ -582,22 +651,12 @@ void Frame::DrainApp(wxProcess* proc, std::ostringstream& oss) { return;
}
- bool first = true;
while (proc->IsInputAvailable()) {
- if (first) {
- first = false;
- oss << " " << "stdout:" << std::endl;
- }
wxTextInputStream iss(*(proc->GetInputStream()));
oss << " " << iss.ReadLine() << std::endl;
}
- first = true;
while (proc->IsErrorAvailable()) {
- if (first) {
- first = false;
- oss << " " << "stderr:" << std::endl;
- }
wxTextInputStream iss(*(proc->GetErrorStream()));
oss << " " << iss.ReadLine() << std::endl;
}
diff --git a/GUI/GUI/GUI/Frame.h b/GUI/GUI/GUI/Frame.h index 35922a1..1d847ca 100644 --- a/GUI/GUI/GUI/Frame.h +++ b/GUI/GUI/GUI/Frame.h @@ -29,8 +29,10 @@ private: wxTextCtrl* unity_parameters_generated_name_;
wxTextCtrl* unity_menu_generated_name_;
+ wxDirPickerCtrl* unity_assets_file_picker_;
wxFilePickerCtrl* unity_animator_file_picker_;
wxFilePickerCtrl* unity_parameters_file_picker_;
+ wxFilePickerCtrl* unity_menu_file_picker_;
wxChoice* py_app_mic_;
wxChoice* py_app_lang_;
diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index 0878560..62a002a 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -2,6 +2,7 @@ #include <stdio.h> +#include <filesystem> #include <sstream> class PythonProcess : public wxProcess { @@ -130,3 +131,67 @@ wxProcess* PythonWrapper::StartApp( std::move(exit_callback)); } +bool PythonWrapper::GenerateAnimator( + const std::string& unity_assets_path, + const std::string& unity_animator_path, + const std::string& unity_parameters_path, + const std::string& unity_menu_path, + const std::string& unity_animator_generated_dir, + const std::string& unity_animator_generated_name, + const std::string& unity_parameters_generated_name, + const std::string& unity_menu_generated_name, + wxTextCtrl* out) { + // Python script locations + std::string libunity_path = "Resources/Scripts/libunity.py"; + std::string libtastt_path = "Resources/Scripts/libtastt.py"; + + // Generated directory locations + std::filesystem::path tastt_generated_dir_path = + std::filesystem::path(unity_assets_path) / unity_animator_generated_dir; + std::filesystem::path guid_map_path = + tastt_generated_dir_path / "guid.map"; + std::filesystem::path tastt_animations_path = + tastt_generated_dir_path / "Animations"; + std::filesystem::path tastt_animator_path = + tastt_generated_dir_path / unity_animator_generated_name; + std::filesystem::path tastt_params_path = + tastt_generated_dir_path / unity_parameters_generated_name; + std::filesystem::path tastt_menu_path = + tastt_generated_dir_path / unity_menu_generated_name; + + { + out->AppendText("Generating guid.map... "); + std::string py_stdout, py_stderr; + if (InvokeWithArgs({ libunity_path, "guid_map", + "--project_root", unity_assets_path, + "--save_to", guid_map_path.string() }, + &py_stdout, &py_stderr)) { + out->AppendText("success!\n"); + out->AppendText(py_stdout.c_str()); + out->AppendText(py_stderr.c_str()); + } + else { + wxLogError("Failed to generate guid.map: %s", py_stderr.c_str()); + out->AppendText("failed!\n"); + } + } + { + out->AppendText("Generating animations... "); + std::string py_stdout, py_stderr; + if (InvokeWithArgs({ libtastt_path, "gen_anims", + "--gen_anim_dir", tastt_animations_path.string(), + "--guid_map", guid_map_path.string() }, + &py_stdout, &py_stderr)) { + out->AppendText("success!\n"); + out->AppendText(py_stdout.c_str()); + out->AppendText(py_stderr.c_str()); + } + else { + wxLogError("Failed to generate animations: %s", py_stderr.c_str()); + out->AppendText("failed!\n"); + } + } + + return true; +} + diff --git a/GUI/GUI/GUI/PythonWrapper.h b/GUI/GUI/GUI/PythonWrapper.h index 6c90087..de5a2e4 100644 --- a/GUI/GUI/GUI/PythonWrapper.h +++ b/GUI/GUI/GUI/PythonWrapper.h @@ -39,5 +39,16 @@ namespace PythonWrapper wxProcess* StartApp( std::function<void(wxProcess* proc, int ret)>&& exit_callback, const std::string& mic, const std::string& lang, const std::string& model); + + bool GenerateAnimator( + const std::string& unity_assets_path, + const std::string& unity_animator_path, + const std::string& unity_parameters_path, + const std::string& unity_menu_path, + const std::string& unity_animator_generated_dir, + const std::string& unity_animator_generated_name, + const std::string& unity_parameters_generated_name, + const std::string& unity_menu_generated_name, + wxTextCtrl* out); }; |
