Updated look of Scene viwer

This commit is contained in:
OusmBlueNinja 2024-12-25 21:14:24 -06:00
parent 7ffcaecbac
commit e5d1cb6096
2 changed files with 34 additions and 24 deletions

BIN
assets/images/SS-Dev1_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

View File

@ -2,17 +2,18 @@
#include "imgui.h"
#include "glm/vec3.hpp"
// Include your asset manager and any other necessary headers
#include "Engine/AssetManager.h"
#include "TestModel.h"
// Globals
extern std::vector<GameObject> g_GameObjects;
extern GameObject* g_SelectedObject;
extern AssetManager g_AssetManager;
// Constructor
// Helper: Create a default cube GameObject
GameObject CreateDefaultCube() {
@ -23,8 +24,7 @@ GameObject CreateDefaultCube() {
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
cube.mesh.vao = CreateCubeVAO(); // Implement your VAO creation logic
cube.mesh.indexCount = 36;
cube.mesh.textureID = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(
g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
cube.mesh.textureID = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
return cube;
}
@ -38,38 +38,42 @@ void SceneWindow::Show() {
ImGui::Separator();
// Begin child region for the list to make it scrollable
ImGui::BeginChild("GameObjectList", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()), false, ImGuiWindowFlags_HorizontalScrollbar);
// List GameObjects
int index = 0;
for (auto it = g_GameObjects.begin(); it != g_GameObjects.end(); ++it, ++index) {
GameObject& obj = *it;
std::string uniqueID = obj.name + "##" + std::to_string(index);
for (int index = 0; index < static_cast<int>(g_GameObjects.size()); ++index) {
GameObject& obj = g_GameObjects[index];
bool isSelected = (g_SelectedObject == &obj);
if (ImGui::TreeNode(uniqueID.c_str())) {
// Select GameObject
if (ImGui::Selectable("Select", g_SelectedObject == &obj)) {
g_SelectedObject = &obj;
}
// 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);
ImGui::EndPopup();
break;
}
// Right-click context menu to remove GameObject
if (ImGui::BeginPopupContextItem()) {
if (ImGui::MenuItem("Remove")) {
RemoveGameObject(index);
ImGui::EndPopup();
break; // Exit the loop as the list has been modified
}
ImGui::TreePop();
ImGui::EndPopup();
}
}
ImGui::EndChild();
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
// 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);
} else {
ImGui::Text("No Object Selected");
}
@ -79,14 +83,20 @@ void SceneWindow::Show() {
// AddGameObject: Adds a new GameObject
void SceneWindow::AddGameObject() {
g_GameObjects.push_back(CreateDefaultCube());
GameObject newObj = CreateDefaultCube();
// Optionally, modify the name to ensure uniqueness
newObj.name += " " + std::to_string(g_GameObjects.size() + 1);
g_GameObjects.push_back(newObj);
}
// RemoveGameObject: Removes a GameObject by index
void SceneWindow::RemoveGameObject(int index) {
if (index >= 0 && index < static_cast<int>(g_GameObjects.size())) {
// If the object to be removed is selected, clear the selection
if (g_SelectedObject == &g_GameObjects[index]) {
g_SelectedObject = nullptr;
}
g_GameObjects.erase(g_GameObjects.begin() + index);
g_SelectedObject = nullptr; // Clear selection if the removed object was selected
}
}