2020#include <iostream>
2121
2222auto framebuffer = Framebuffer::get_default(1920, 1080);
23+ auto focus_on_scene = false;
2324
2425void glfw_error_callback([[maybe_unused]] int error, char const* description)
2526{
@@ -53,7 +54,7 @@ void setup_dock_builder()
5354 }
5455}
5556
56- int main()
57+ int main(int argc, char** argv )
5758{
5859 glfwSetErrorCallback(glfw_error_callback);
5960
@@ -102,26 +103,41 @@ int main()
102103 Input::init(window);
103104 AsyncTaskQueue::init();
104105
106+ if (argc == 2) {
107+ auto input_path = std::filesystem::path{argv[1]};
108+ if (input_path.is_relative()) {
109+ input_path = std::filesystem::canonical(std::filesystem::current_path() / input_path);
110+ }
111+ if (std::filesystem::is_directory(input_path)) {
112+ Project::load(input_path);
113+ if (!Project::get_current()->scene) {
114+ Project::get_current()->scene = std::make_unique<InstancedNode>();
115+ }
116+ } else if (std::filesystem::is_regular_file(input_path)) {
117+ Project::load(std::filesystem::current_path());
118+ auto project = Project::get_current();
119+ if (!project->scene) {
120+ project->scene = std::make_unique<InstancedNode>();
121+ auto obj = project->get_model(input_path);
122+ if (obj) {
123+ project->scene->children.push_back(obj->instantiate());
124+ focus_on_scene = true;
125+ }
126+ }
127+ }
128+ }
129+
105130 // assuming we set the CWD to root
106131 // TODO: Replace with some kind of "Open Project" dialog
132+ // legacy behaviour
107133 auto path = std::filesystem::current_path() / "assets";
108- std::cout << path.string().c_str() << std::endl;
109- Project::load(path);
134+ if (!Project::get_current()) {
135+ std::cout << path.string().c_str() << std::endl;
136+ Project::load(path);
137+ }
110138
111139 auto project = Project::get_current();
112140
113- // Instanciate the object if it didn't get loaded
114- // TODO: Remove when objects can be added at runtime
115-
116- // This is just some temporary workaround
117- auto root_transform = Transform{
118- .position = glm::vec3{0.0f, -15000.0f, -4000.0f},
119- .orientation = glm::vec3{0.0f},
120- .scale = glm::vec3{1.0f},
121- };
122-
123- auto scene = Node::create("scene", root_transform, NodeLocation::empty());
124-
125141 if (!project->scene) {
126142 auto model_path = path / "Models/TUD_Innenstadt.FBX";
127143 auto obj = project->get_model(model_path);
@@ -130,9 +146,21 @@ int main()
130146 std::abort();
131147 }
132148
133- scene.children.push_back(*obj);
134-
135- project->scene = scene.instantiate();
149+ // This is just some temporary workaround
150+ auto root_transform = Transform{
151+ .position = glm::vec3{0.0f, -15000.0f, -4000.0f},
152+ .orientation = glm::vec3{0.0f},
153+ .scale = glm::vec3{1.0f},
154+ };
155+
156+ project->scene = std::unique_ptr<InstancedNode>(new InstancedNode{
157+ .transform = root_transform,
158+ .node = nullptr,
159+ .children = {},
160+ .name = "scene",
161+ });
162+
163+ project->scene->children.push_back(obj->instantiate());
136164 }
137165
138166 if (!project->scene) {
@@ -183,6 +211,11 @@ int main()
183211 performance_window.render(delta_time);
184212#endif
185213
214+ if (focus_on_scene) {
215+ focus_on_scene = false;
216+ viewport_window.camera_controller().focus_on(*project->scene);
217+ }
218+
186219 ImGui::Render();
187220 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
188221
0 commit comments