关键节点
This commit is contained in:
188
editor/app/Scene/EditorSceneRuntime.h
Normal file
188
editor/app/Scene/EditorSceneRuntime.h
Normal file
@@ -0,0 +1,188 @@
|
||||
#pragma once
|
||||
|
||||
#include "Scene/EditorSceneBridge.h"
|
||||
#include "Scene/SceneViewportCameraController.h"
|
||||
#include "Scene/SceneToolState.h"
|
||||
#include "State/EditorSelectionService.h"
|
||||
#include "Rendering/Viewport/SceneViewportRenderRequest.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 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:
|
||||
EditorSceneRuntime() = default;
|
||||
EditorSceneRuntime(const EditorSceneRuntime&) = delete;
|
||||
EditorSceneRuntime& operator=(const EditorSceneRuntime&) = delete;
|
||||
EditorSceneRuntime(EditorSceneRuntime&&) = delete;
|
||||
EditorSceneRuntime& operator=(EditorSceneRuntime&&) = delete;
|
||||
|
||||
void Reset();
|
||||
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<EditorSceneComponentDescriptor> GetSelectedComponents() const;
|
||||
std::uint64_t GetSelectionStamp() const;
|
||||
std::uint64_t GetInspectorRevision() 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 MoveGameObjectBefore(
|
||||
std::string_view itemId,
|
||||
std::string_view targetItemId);
|
||||
bool MoveGameObjectAfter(
|
||||
std::string_view itemId,
|
||||
std::string_view targetItemId);
|
||||
bool MoveGameObjectToRoot(std::string_view itemId);
|
||||
bool AddComponentToSelectedGameObject(std::string_view componentTypeName);
|
||||
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();
|
||||
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();
|
||||
void IncrementInspectorRevision();
|
||||
|
||||
std::filesystem::path m_projectRoot = {};
|
||||
EditorStartupSceneResult m_startupSceneResult = {};
|
||||
EditorSelectionService m_ownedSelectionService = {};
|
||||
EditorSelectionService* m_selectionService = &m_ownedSelectionService;
|
||||
SceneViewCameraState m_sceneViewCamera = {};
|
||||
SceneToolState m_toolState = {};
|
||||
std::vector<TransformEditTransaction> m_transformUndoStack = {};
|
||||
std::vector<TransformEditTransaction> m_transformRedoStack = {};
|
||||
std::uint64_t m_inspectorRevision = 0u;
|
||||
};
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
Reference in New Issue
Block a user