|
20 | 20 | #include <iostream> |
21 | 21 |
|
22 | 22 | auto framebuffer = Framebuffer::get_default(1920, 1080); |
| 23 | +auto focus_on_scene = false; |
23 | 24 |
|
24 | 25 | void glfw_error_callback([[maybe_unused]] int error, char const* description) |
25 | 26 | { |
@@ -53,7 +54,7 @@ void setup_dock_builder() |
53 | 54 | } |
54 | 55 | } |
55 | 56 |
|
56 | | -int main() |
| 57 | +int main(int argc, char** argv) |
57 | 58 | { |
58 | 59 | glfwSetErrorCallback(glfw_error_callback); |
59 | 60 |
|
@@ -102,40 +103,37 @@ int main() |
102 | 103 | Input::init(window); |
103 | 104 | AsyncTaskQueue::init(); |
104 | 105 |
|
105 | | - // assuming we set the CWD to root |
106 | | - // TODO: Replace with some kind of "Open Project" dialog |
107 | | - auto path = std::filesystem::current_path() / "assets"; |
108 | | - std::cout << path.string().c_str() << std::endl; |
109 | | - Project::load(path); |
| 106 | + auto input_path = std::filesystem::current_path(); |
110 | 107 |
|
111 | | - auto project = Project::get_current(); |
112 | | - |
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 | | - |
125 | | - if (!project->scene) { |
126 | | - auto model_path = path / "Models/TUD_Innenstadt.FBX"; |
127 | | - auto obj = project->get_model(model_path); |
| 108 | + if (argc == 2) { |
| 109 | + input_path = std::filesystem::path{argv[1]}; |
| 110 | + if (input_path.is_relative()) { |
| 111 | + input_path = std::filesystem::canonical(std::filesystem::current_path() / input_path); |
| 112 | + } |
| 113 | + } |
128 | 114 |
|
129 | | - if (!obj) { |
130 | | - std::abort(); |
| 115 | + if (std::filesystem::is_directory(input_path)) { |
| 116 | + auto project = Project::load(input_path); |
| 117 | + if (!project->scene) { |
| 118 | + project->scene = std::make_unique<InstancedNode>(); |
131 | 119 | } |
| 120 | + } else if (std::filesystem::is_regular_file(input_path)) { |
| 121 | + auto project = Project::load(std::filesystem::current_path()); |
| 122 | + if (!project->scene) { |
| 123 | + project->scene = std::make_unique<InstancedNode>(); |
| 124 | + auto obj = project->get_model(input_path); |
| 125 | + if (obj) { |
| 126 | + project->scene->children.push_back(obj->instantiate()); |
| 127 | + focus_on_scene = true; |
| 128 | + } |
| 129 | + } |
| 130 | + } |
132 | 131 |
|
133 | | - scene.children.push_back(*obj); |
| 132 | + // TODO: Add with some kind of "Open Project" dialog |
134 | 133 |
|
135 | | - project->scene = scene.instantiate(); |
136 | | - } |
| 134 | + auto project = Project::get_current(); |
137 | 135 |
|
138 | | - if (!project->scene) { |
| 136 | + if (!project || !project->scene) { |
139 | 137 | std::abort(); |
140 | 138 | } |
141 | 139 |
|
@@ -183,6 +181,11 @@ int main() |
183 | 181 | performance_window.render(delta_time); |
184 | 182 | #endif |
185 | 183 |
|
| 184 | + if (focus_on_scene) { |
| 185 | + focus_on_scene = false; |
| 186 | + viewport_window.camera_controller().focus_on(*project->scene); |
| 187 | + } |
| 188 | + |
186 | 189 | ImGui::Render(); |
187 | 190 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
188 | 191 |
|
|
0 commit comments