#pragma once #include "Scene/EditorSceneBridge.h" #include "Scene/SceneViewportCameraController.h" #include "Scene/SceneToolState.h" #include "State/EditorSelectionService.h" #include #include #include #include #include #include #include #include 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 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 BindSelectionService(EditorSelectionService* selectionService); 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 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& 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(); EditorSelectionService& SelectionService(); const EditorSelectionService& SelectionService() const; bool HasHierarchySelection() const; void RevalidateSelection(); 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 = {}; EditorSelectionService m_ownedSelectionService = {}; EditorSelectionService* m_selectionService = &m_ownedSelectionService; SceneViewCameraState m_sceneViewCamera = {}; SceneToolState m_toolState = {}; std::vector m_transformUndoStack = {}; std::vector m_transformRedoStack = {}; }; } // namespace XCEngine::UI::Editor::App