2024-12-26 03:06:17 +00:00
|
|
|
#include "SceneWindow.h"
|
|
|
|
#include "imgui.h"
|
|
|
|
#include "glm/vec3.hpp"
|
|
|
|
|
2024-12-26 03:14:24 +00:00
|
|
|
// Include your asset manager and any other necessary headers
|
2024-12-26 03:06:17 +00:00
|
|
|
#include "Engine/AssetManager.h"
|
|
|
|
#include "TestModel.h"
|
|
|
|
|
|
|
|
// Globals
|
|
|
|
extern std::vector<GameObject> g_GameObjects;
|
|
|
|
extern GameObject* g_SelectedObject;
|
|
|
|
|
|
|
|
|
2024-12-26 03:14:24 +00:00
|
|
|
extern AssetManager g_AssetManager;
|
2024-12-26 03:06:17 +00:00
|
|
|
|
2024-12-26 03:14:24 +00:00
|
|
|
// Constructor
|
2024-12-26 03:06:17 +00:00
|
|
|
|
|
|
|
// Helper: Create a default cube GameObject
|
|
|
|
GameObject CreateDefaultCube() {
|
|
|
|
GameObject cube;
|
|
|
|
cube.name = "Cube";
|
|
|
|
cube.transform.position = glm::vec3(0.f, 0.f, 0.f);
|
|
|
|
cube.transform.rotation = glm::vec3(0.f, 0.5f, 0.f);
|
|
|
|
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
|
|
|
|
cube.mesh.vao = CreateCubeVAO(); // Implement your VAO creation logic
|
|
|
|
cube.mesh.indexCount = 36;
|
2024-12-26 03:14:24 +00:00
|
|
|
cube.mesh.textureID = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
|
2024-12-26 03:06:17 +00:00
|
|
|
return cube;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show function implementation
|
|
|
|
void SceneWindow::Show() {
|
|
|
|
if (ImGui::Begin("Scene Window")) {
|
|
|
|
// Add Button
|
|
|
|
if (ImGui::Button("Add Object")) {
|
|
|
|
AddGameObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2024-12-26 03:14:24 +00:00
|
|
|
// Begin child region for the list to make it scrollable
|
|
|
|
ImGui::BeginChild("GameObjectList", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()), false, ImGuiWindowFlags_HorizontalScrollbar);
|
|
|
|
|
2024-12-26 03:06:17 +00:00
|
|
|
// List GameObjects
|
2024-12-26 03:14:24 +00:00
|
|
|
for (int index = 0; index < static_cast<int>(g_GameObjects.size()); ++index) {
|
|
|
|
GameObject& obj = g_GameObjects[index];
|
|
|
|
bool isSelected = (g_SelectedObject == &obj);
|
2024-12-26 03:06:17 +00:00
|
|
|
|
2024-12-26 03:14:24 +00:00
|
|
|
// Create a selectable item for each GameObject
|
|
|
|
if (ImGui::Selectable(obj.name.c_str(), isSelected)) {
|
|
|
|
g_SelectedObject = &obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right-click context menu to remove GameObject
|
|
|
|
if (ImGui::BeginPopupContextItem()) {
|
|
|
|
if (ImGui::MenuItem("Remove")) {
|
|
|
|
RemoveGameObject(index);
|
2024-12-26 03:06:17 +00:00
|
|
|
ImGui::EndPopup();
|
2024-12-26 03:14:24 +00:00
|
|
|
break; // Exit the loop as the list has been modified
|
2024-12-26 03:06:17 +00:00
|
|
|
}
|
2024-12-26 03:14:24 +00:00
|
|
|
ImGui::EndPopup();
|
2024-12-26 03:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-26 03:14:24 +00:00
|
|
|
ImGui::EndChild();
|
|
|
|
|
2024-12-26 03:06:17 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
// Show currently selected object details at the bottom
|
|
|
|
if (g_SelectedObject) {
|
|
|
|
ImGui::Text("Selected Object: %s", g_SelectedObject->name.c_str());
|
|
|
|
// Optionally add details or editable fields here
|
2024-12-26 03:14:24 +00:00
|
|
|
// Example:
|
|
|
|
// ImGui::DragFloat3("Position", &g_SelectedObject->transform.position.x, 0.1f);
|
|
|
|
// ImGui::DragFloat3("Rotation", &g_SelectedObject->transform.rotation.x, 0.1f);
|
|
|
|
// ImGui::DragFloat3("Scale", &g_SelectedObject->transform.scale.x, 0.1f);
|
2024-12-26 03:06:17 +00:00
|
|
|
} else {
|
|
|
|
ImGui::Text("No Object Selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddGameObject: Adds a new GameObject
|
|
|
|
void SceneWindow::AddGameObject() {
|
2024-12-26 03:14:24 +00:00
|
|
|
GameObject newObj = CreateDefaultCube();
|
|
|
|
// Optionally, modify the name to ensure uniqueness
|
|
|
|
newObj.name += " " + std::to_string(g_GameObjects.size() + 1);
|
|
|
|
g_GameObjects.push_back(newObj);
|
2024-12-26 03:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveGameObject: Removes a GameObject by index
|
|
|
|
void SceneWindow::RemoveGameObject(int index) {
|
|
|
|
if (index >= 0 && index < static_cast<int>(g_GameObjects.size())) {
|
2024-12-26 03:14:24 +00:00
|
|
|
// If the object to be removed is selected, clear the selection
|
|
|
|
if (g_SelectedObject == &g_GameObjects[index]) {
|
|
|
|
g_SelectedObject = nullptr;
|
|
|
|
}
|
2024-12-26 03:06:17 +00:00
|
|
|
g_GameObjects.erase(g_GameObjects.begin() + index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSelectedObject function implementation
|
|
|
|
GameObject* SceneWindow::GetSelectedObject() const {
|
|
|
|
return g_SelectedObject;
|
|
|
|
}
|