177 lines
6.2 KiB
C++
177 lines
6.2 KiB
C++
#pragma once
|
|
|
|
#include "Scene/EditorSceneBridge.h"
|
|
#include "Scene/SceneViewportCameraController.h"
|
|
#include "Scene/SceneToolState.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <filesystem>
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace XCEngine::Components {
|
|
|
|
class CameraComponent;
|
|
class Component;
|
|
class GameObject;
|
|
class Scene;
|
|
|
|
} // namespace XCEngine::Components
|
|
|
|
namespace XCEngine::Math {
|
|
|
|
struct Vector3;
|
|
|
|
} // namespace XCEngine::Math
|
|
|
|
namespace XCEngine::UI::Editor::App {
|
|
|
|
struct SceneViewportRenderRequest {
|
|
::XCEngine::Components::Scene* scene = nullptr;
|
|
::XCEngine::Components::CameraComponent* camera = nullptr;
|
|
std::vector<std::uint64_t> selectedObjectIds = {};
|
|
float orbitDistance = 0.0f;
|
|
bool debugSelectionMask = false;
|
|
|
|
bool IsValid() const {
|
|
return scene != nullptr && camera != nullptr;
|
|
}
|
|
};
|
|
|
|
struct EditorSceneComponentDescriptor {
|
|
std::string componentId = {};
|
|
std::string typeName = {};
|
|
const ::XCEngine::Components::Component* component = nullptr;
|
|
bool removable = false;
|
|
|
|
bool IsValid() const {
|
|
return !componentId.empty() &&
|
|
!typeName.empty() &&
|
|
component != nullptr;
|
|
}
|
|
};
|
|
|
|
class EditorSceneRuntime {
|
|
public:
|
|
bool Initialize(const std::filesystem::path& projectRoot);
|
|
|
|
void RefreshScene();
|
|
void EnsureSceneSelection();
|
|
|
|
const EditorStartupSceneResult& GetStartupResult() const;
|
|
::XCEngine::Components::Scene* GetActiveScene() const;
|
|
::XCEngine::Components::CameraComponent* GetSceneViewCamera();
|
|
const ::XCEngine::Components::CameraComponent* GetSceneViewCamera() const;
|
|
float GetSceneViewOrbitDistance() const;
|
|
SceneViewportRenderRequest BuildSceneViewportRenderRequest();
|
|
void ApplySceneViewportCameraInput(const SceneViewportCameraInputState& input);
|
|
bool FocusSceneSelection();
|
|
|
|
bool HasSceneSelection() const;
|
|
std::optional<::XCEngine::Components::GameObject::ID> GetSelectedGameObjectId() const;
|
|
std::string GetSelectedItemId() const;
|
|
std::string GetSelectedDisplayName() const;
|
|
const ::XCEngine::Components::GameObject* GetSelectedGameObject() const;
|
|
std::vector<EditorSceneComponentDescriptor> GetSelectedComponents() const;
|
|
std::uint64_t GetSelectionStamp() const;
|
|
|
|
bool SetSelection(std::string_view itemId);
|
|
bool SetSelection(::XCEngine::Components::GameObject::ID id);
|
|
void ClearSelection();
|
|
bool OpenSceneAsset(const std::filesystem::path& scenePath);
|
|
|
|
::XCEngine::Components::GameObject* FindGameObject(std::string_view itemId) const;
|
|
bool RenameGameObject(
|
|
std::string_view itemId,
|
|
std::string_view newName);
|
|
bool DeleteGameObject(std::string_view itemId);
|
|
std::string DuplicateGameObject(std::string_view itemId);
|
|
bool ReparentGameObject(
|
|
std::string_view itemId,
|
|
std::string_view parentItemId);
|
|
bool MoveGameObjectToRoot(std::string_view itemId);
|
|
bool CanRemoveSelectedComponent(std::string_view componentId) const;
|
|
bool RemoveSelectedComponent(std::string_view componentId);
|
|
bool SetSelectedTransformLocalPosition(
|
|
std::string_view componentId,
|
|
const ::XCEngine::Math::Vector3& position);
|
|
bool SetSelectedTransformLocalEulerAngles(
|
|
std::string_view componentId,
|
|
const ::XCEngine::Math::Vector3& eulerAngles);
|
|
bool SetSelectedTransformLocalScale(
|
|
std::string_view componentId,
|
|
const ::XCEngine::Math::Vector3& scale);
|
|
bool ApplySelectedComponentMutation(
|
|
std::string_view componentId,
|
|
const std::function<bool(::XCEngine::Components::Component&)>& mutation);
|
|
|
|
const SceneToolState& GetToolState() const;
|
|
SceneToolMode GetToolMode() const;
|
|
SceneToolSpaceMode GetToolSpaceMode() const;
|
|
SceneToolPivotMode GetToolPivotMode() const;
|
|
void SetToolMode(SceneToolMode mode);
|
|
void SetToolSpaceMode(SceneToolSpaceMode mode);
|
|
void SetToolPivotMode(SceneToolPivotMode mode);
|
|
void SetHoveredToolHandle(SceneToolHandle handle);
|
|
void SetToolInteractionLock(SceneToolInteractionLock lock);
|
|
void ClearToolInteractionLock();
|
|
void ResetToolInteractionState();
|
|
|
|
bool CaptureSelectedTransformSnapshot(SceneTransformSnapshot& outSnapshot) const;
|
|
bool ApplyTransformSnapshot(const SceneTransformSnapshot& snapshot);
|
|
bool RecordTransformEdit(
|
|
const SceneTransformSnapshot& before,
|
|
const SceneTransformSnapshot& after);
|
|
bool BeginTransformToolDrag(
|
|
SceneToolHandle handle,
|
|
const ::XCEngine::UI::UIPoint& startPointerPosition);
|
|
bool HasActiveTransformToolDrag() const;
|
|
const SceneToolDragState* GetActiveTransformToolDrag() const;
|
|
bool ApplyTransformToolPreview(const SceneTransformSnapshot& snapshot);
|
|
bool CommitTransformToolDrag();
|
|
void CancelTransformToolDrag();
|
|
|
|
bool CanUndoTransformEdit() const;
|
|
bool CanRedoTransformEdit() const;
|
|
bool UndoTransformEdit();
|
|
bool RedoTransformEdit();
|
|
|
|
private:
|
|
struct SceneViewCameraState {
|
|
std::unique_ptr<::XCEngine::Components::GameObject> gameObject = {};
|
|
::XCEngine::Components::CameraComponent* camera = nullptr;
|
|
SceneViewportCameraController controller = {};
|
|
};
|
|
|
|
struct TransformEditTransaction {
|
|
SceneTransformSnapshot before = {};
|
|
SceneTransformSnapshot after = {};
|
|
};
|
|
|
|
bool EnsureSceneViewCamera();
|
|
void ApplySceneViewCameraController();
|
|
bool HasValidSelection() const;
|
|
EditorSceneComponentDescriptor ResolveSelectedComponentDescriptor(
|
|
std::string_view componentId) const;
|
|
bool SelectFirstAvailableGameObject();
|
|
void ResetTransformEditHistory();
|
|
void ResetToolInteractionTransientState();
|
|
void ClearInvalidToolInteractionState();
|
|
|
|
std::filesystem::path m_projectRoot = {};
|
|
EditorStartupSceneResult m_startupSceneResult = {};
|
|
std::optional<::XCEngine::Components::GameObject::ID> m_selectedGameObjectId = std::nullopt;
|
|
std::uint64_t m_selectionStamp = 0u;
|
|
SceneViewCameraState m_sceneViewCamera = {};
|
|
SceneToolState m_toolState = {};
|
|
std::vector<TransformEditTransaction> m_transformUndoStack = {};
|
|
std::vector<TransformEditTransaction> m_transformRedoStack = {};
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|