Updated look of Scene viwer
This commit is contained in:
parent
7ffcaecbac
commit
e5d1cb6096
BIN
assets/images/SS-Dev1_2.png
Normal file
BIN
assets/images/SS-Dev1_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 118 KiB |
@ -2,17 +2,18 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "glm/vec3.hpp"
|
#include "glm/vec3.hpp"
|
||||||
|
|
||||||
|
// Include your asset manager and any other necessary headers
|
||||||
#include "Engine/AssetManager.h"
|
#include "Engine/AssetManager.h"
|
||||||
|
|
||||||
#include "TestModel.h"
|
#include "TestModel.h"
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
extern std::vector<GameObject> g_GameObjects;
|
extern std::vector<GameObject> g_GameObjects;
|
||||||
extern GameObject* g_SelectedObject;
|
extern GameObject* g_SelectedObject;
|
||||||
|
|
||||||
|
|
||||||
extern AssetManager g_AssetManager;
|
extern AssetManager g_AssetManager;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
|
||||||
// Helper: Create a default cube GameObject
|
// Helper: Create a default cube GameObject
|
||||||
GameObject CreateDefaultCube() {
|
GameObject CreateDefaultCube() {
|
||||||
@ -23,8 +24,7 @@ GameObject CreateDefaultCube() {
|
|||||||
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
|
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
|
||||||
cube.mesh.vao = CreateCubeVAO(); // Implement your VAO creation logic
|
cube.mesh.vao = CreateCubeVAO(); // Implement your VAO creation logic
|
||||||
cube.mesh.indexCount = 36;
|
cube.mesh.indexCount = 36;
|
||||||
cube.mesh.textureID = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(
|
cube.mesh.textureID = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
|
||||||
g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
|
|
||||||
return cube;
|
return cube;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,38 +38,42 @@ void SceneWindow::Show() {
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Begin child region for the list to make it scrollable
|
||||||
|
ImGui::BeginChild("GameObjectList", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
|
|
||||||
// List GameObjects
|
// List GameObjects
|
||||||
int index = 0;
|
for (int index = 0; index < static_cast<int>(g_GameObjects.size()); ++index) {
|
||||||
for (auto it = g_GameObjects.begin(); it != g_GameObjects.end(); ++it, ++index) {
|
GameObject& obj = g_GameObjects[index];
|
||||||
GameObject& obj = *it;
|
bool isSelected = (g_SelectedObject == &obj);
|
||||||
std::string uniqueID = obj.name + "##" + std::to_string(index);
|
|
||||||
|
|
||||||
if (ImGui::TreeNode(uniqueID.c_str())) {
|
// Create a selectable item for each GameObject
|
||||||
// Select GameObject
|
if (ImGui::Selectable(obj.name.c_str(), isSelected)) {
|
||||||
if (ImGui::Selectable("Select", g_SelectedObject == &obj)) {
|
g_SelectedObject = &obj;
|
||||||
g_SelectedObject = &obj;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Right-click context menu to remove GameObject
|
// Right-click context menu to remove GameObject
|
||||||
if (ImGui::BeginPopupContextItem()) {
|
if (ImGui::BeginPopupContextItem()) {
|
||||||
if (ImGui::MenuItem("Remove")) {
|
if (ImGui::MenuItem("Remove")) {
|
||||||
RemoveGameObject(index);
|
RemoveGameObject(index);
|
||||||
ImGui::EndPopup();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
break; // Exit the loop as the list has been modified
|
||||||
}
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
ImGui::TreePop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::EndChild();
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
// Show currently selected object details at the bottom
|
// Show currently selected object details at the bottom
|
||||||
if (g_SelectedObject) {
|
if (g_SelectedObject) {
|
||||||
ImGui::Text("Selected Object: %s", g_SelectedObject->name.c_str());
|
ImGui::Text("Selected Object: %s", g_SelectedObject->name.c_str());
|
||||||
// Optionally add details or editable fields here
|
// 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 {
|
} else {
|
||||||
ImGui::Text("No Object Selected");
|
ImGui::Text("No Object Selected");
|
||||||
}
|
}
|
||||||
@ -79,14 +83,20 @@ void SceneWindow::Show() {
|
|||||||
|
|
||||||
// AddGameObject: Adds a new GameObject
|
// AddGameObject: Adds a new GameObject
|
||||||
void SceneWindow::AddGameObject() {
|
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
|
// RemoveGameObject: Removes a GameObject by index
|
||||||
void SceneWindow::RemoveGameObject(int index) {
|
void SceneWindow::RemoveGameObject(int index) {
|
||||||
if (index >= 0 && index < static_cast<int>(g_GameObjects.size())) {
|
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_GameObjects.erase(g_GameObjects.begin() + index);
|
||||||
g_SelectedObject = nullptr; // Clear selection if the removed object was selected
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user