更新 Source/FLESHEditor/Public/FLESHEditor.h
This commit is contained in:
@@ -2,60 +2,340 @@
|
|||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Toolkits/AssetEditorToolkit.h"
|
#include "Toolkits/AssetEditorToolkit.h"
|
||||||
#include "EditorUndoClient.h"
|
#include "Widgets/Docking/SDockTab.h"
|
||||||
|
#include "BooleanCutTool.h"
|
||||||
|
|
||||||
class USkeletalMesh;
|
|
||||||
class SDockTab;
|
class SDockTab;
|
||||||
class IDetailsView;
|
class SGraphEditor;
|
||||||
class SBorder;
|
class SPropertyTreeView;
|
||||||
|
class SAssetBrowser;
|
||||||
|
class SMatrixInputWidget;
|
||||||
|
class FFLESHViewportClient;
|
||||||
|
class FSceneViewport;
|
||||||
|
class UVisceraNodeObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismemberment System Editor
|
* Bone tree item structure
|
||||||
* Provides real-time boolean cutting and multi-layer system editing functionality
|
|
||||||
*/
|
*/
|
||||||
class FDismembermentEditor : public FAssetEditorToolkit, public FEditorUndoClient
|
struct FBoneTreeItem : public TSharedFromThis<FBoneTreeItem>
|
||||||
|
{
|
||||||
|
// Bone name
|
||||||
|
FName BoneName;
|
||||||
|
|
||||||
|
// Display name for UI
|
||||||
|
FString DisplayName;
|
||||||
|
|
||||||
|
// Bone type (e.g., "Root", "Limb", "Joint", etc.)
|
||||||
|
FString BoneType;
|
||||||
|
|
||||||
|
// Parent bone item
|
||||||
|
TWeakPtr<FBoneTreeItem> ParentItem;
|
||||||
|
|
||||||
|
// Child bone items
|
||||||
|
TArray<TSharedPtr<FBoneTreeItem>> Children;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FBoneTreeItem(FName InBoneName, const FString& InDisplayName, const FString& InBoneType = TEXT(""))
|
||||||
|
: BoneName(InBoneName)
|
||||||
|
, DisplayName(InDisplayName)
|
||||||
|
, BoneType(InBoneType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a child bone
|
||||||
|
void AddChild(TSharedPtr<FBoneTreeItem> Child)
|
||||||
|
{
|
||||||
|
Children.Add(Child);
|
||||||
|
Child->ParentItem = SharedThis(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Viscera node item structure
|
||||||
|
*/
|
||||||
|
struct FVisceraNodeItem : public TSharedFromThis<FVisceraNodeItem>
|
||||||
|
{
|
||||||
|
// Node name
|
||||||
|
FName NodeName;
|
||||||
|
|
||||||
|
// Display name for UI
|
||||||
|
FString DisplayName;
|
||||||
|
|
||||||
|
// Node type (e.g., "SoftBody", "Anchor", "Collision", "Tetra", "LineChain", "Plane", etc.)
|
||||||
|
FString NodeType;
|
||||||
|
|
||||||
|
// Parent node item
|
||||||
|
TWeakPtr<FVisceraNodeItem> ParentItem;
|
||||||
|
|
||||||
|
// Child node items
|
||||||
|
TArray<TSharedPtr<FVisceraNodeItem>> Children;
|
||||||
|
|
||||||
|
// Physical properties
|
||||||
|
TMap<FName, float> FloatProperties;
|
||||||
|
TMap<FName, FVector> VectorProperties;
|
||||||
|
TMap<FName, FName> NameProperties;
|
||||||
|
TMap<FName, bool> BoolProperties;
|
||||||
|
TArray<FVector> PointsArray;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FVisceraNodeItem(FName InNodeName, const FString& InDisplayName, const FString& InNodeType = TEXT(""))
|
||||||
|
: NodeName(InNodeName)
|
||||||
|
, DisplayName(InDisplayName)
|
||||||
|
, NodeType(InNodeType)
|
||||||
|
{
|
||||||
|
// Initialize default properties based on node type
|
||||||
|
if (InNodeType.Equals(TEXT("SoftBody")))
|
||||||
|
{
|
||||||
|
// Default SoftBody properties
|
||||||
|
FloatProperties.Add(TEXT("GravityStrength"), 1.0f);
|
||||||
|
FloatProperties.Add(TEXT("MinFrameSpeed"), 0.0f);
|
||||||
|
FloatProperties.Add(TEXT("MaxFrameSpeed"), 200.0f);
|
||||||
|
FloatProperties.Add(TEXT("ExternalFrameLerp"), 1.0f);
|
||||||
|
FloatProperties.Add(TEXT("InitialGPUInfluence"), 0.5f);
|
||||||
|
FloatProperties.Add(TEXT("SubstepTime"), 0.01667f);
|
||||||
|
FloatProperties.Add(TEXT("SolverIterations"), 1.0f);
|
||||||
|
BoolProperties.Add(TEXT("EnableSimulation"), true);
|
||||||
|
BoolProperties.Add(TEXT("RecomputeNormals"), true);
|
||||||
|
}
|
||||||
|
else if (InNodeType.Equals(TEXT("Anchor")))
|
||||||
|
{
|
||||||
|
// Default Anchor properties
|
||||||
|
FloatProperties.Add(TEXT("Radius"), 5.0f);
|
||||||
|
FloatProperties.Add(TEXT("Stiffness"), 1.0f);
|
||||||
|
VectorProperties.Add(TEXT("Location"), FVector::ZeroVector);
|
||||||
|
NameProperties.Add(TEXT("BoneName"), NAME_None);
|
||||||
|
}
|
||||||
|
else if (InNodeType.Equals(TEXT("LineChain")))
|
||||||
|
{
|
||||||
|
// Default LineChain properties
|
||||||
|
FloatProperties.Add(TEXT("Stiffness"), 0.5f);
|
||||||
|
FloatProperties.Add(TEXT("Thickness"), 1.0f);
|
||||||
|
// Default with two points
|
||||||
|
PointsArray.Add(FVector(-10.0f, 0.0f, 0.0f));
|
||||||
|
PointsArray.Add(FVector(10.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
else if (InNodeType.Equals(TEXT("Tetra")))
|
||||||
|
{
|
||||||
|
// Default Tetra properties
|
||||||
|
FloatProperties.Add(TEXT("Stiffness"), 0.7f);
|
||||||
|
// Default tetrahedron points
|
||||||
|
PointsArray.Add(FVector(0.0f, 0.0f, 0.0f));
|
||||||
|
PointsArray.Add(FVector(10.0f, 0.0f, 0.0f));
|
||||||
|
PointsArray.Add(FVector(0.0f, 10.0f, 0.0f));
|
||||||
|
PointsArray.Add(FVector(0.0f, 0.0f, 10.0f));
|
||||||
|
}
|
||||||
|
else if (InNodeType.Equals(TEXT("Plane")))
|
||||||
|
{
|
||||||
|
// Default Plane properties
|
||||||
|
FloatProperties.Add(TEXT("Stiffness"), 1.0f);
|
||||||
|
VectorProperties.Add(TEXT("Location"), FVector::ZeroVector);
|
||||||
|
VectorProperties.Add(TEXT("Normal"), FVector::UpVector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a child node
|
||||||
|
void AddChild(TSharedPtr<FVisceraNodeItem> Child)
|
||||||
|
{
|
||||||
|
Children.Add(Child);
|
||||||
|
Child->ParentItem = SharedThis(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a float property
|
||||||
|
void SetFloatProperty(FName PropertyName, float Value)
|
||||||
|
{
|
||||||
|
FloatProperties.Add(PropertyName, Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a vector property
|
||||||
|
void SetVectorProperty(FName PropertyName, const FVector& Value)
|
||||||
|
{
|
||||||
|
VectorProperties.Add(PropertyName, Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a name property
|
||||||
|
void SetNameProperty(FName PropertyName, FName Value)
|
||||||
|
{
|
||||||
|
NameProperties.Add(PropertyName, Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a bool property
|
||||||
|
void SetBoolProperty(FName PropertyName, bool Value)
|
||||||
|
{
|
||||||
|
BoolProperties.Add(PropertyName, Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a point to the points array
|
||||||
|
void AddPoint(const FVector& Point)
|
||||||
|
{
|
||||||
|
PointsArray.Add(Point);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear all points
|
||||||
|
void ClearPoints()
|
||||||
|
{
|
||||||
|
PointsArray.Empty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FLESH Main Editor
|
||||||
|
* Provides the main editing functionality for the dismemberment system
|
||||||
|
*/
|
||||||
|
class FLESHEDITOR_API FFLESHEditor : public FAssetEditorToolkit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FDismembermentEditor();
|
FFLESHEditor();
|
||||||
virtual ~FDismembermentEditor();
|
virtual ~FFLESHEditor();
|
||||||
|
|
||||||
void InitDismembermentEditor(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost>& InitToolkitHost, USkeletalMesh* InSkeletalMesh);
|
// Initialize the editor
|
||||||
|
void InitFLESHEditor(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost>& InitToolkitHost, UObject* InObject);
|
||||||
virtual FName GetToolkitFName() const override;
|
|
||||||
virtual FText GetBaseToolkitName() const override;
|
// FAssetEditorToolkit interface
|
||||||
virtual FString GetWorldCentricTabPrefix() const override;
|
virtual void RegisterTabSpawners(const TSharedRef<FTabManager>& TabManager) override;
|
||||||
virtual FLinearColor GetWorldCentricTabColorScale() const override;
|
virtual void UnregisterTabSpawners(const TSharedRef<FTabManager>& TabManager) override;
|
||||||
|
virtual FName GetToolkitFName() const override;
|
||||||
virtual void PostUndo(bool bSuccess) override;
|
virtual FText GetBaseToolkitName() const override;
|
||||||
virtual void PostRedo(bool bSuccess) override;
|
virtual FString GetWorldCentricTabPrefix() const override;
|
||||||
|
virtual FLinearColor GetWorldCentricTabColorScale() const override;
|
||||||
|
// End of FAssetEditorToolkit interface
|
||||||
|
|
||||||
|
// Open the editor
|
||||||
|
static void OpenEditor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateEditorLayout();
|
// Tab spawners
|
||||||
void CreateEditorToolbar();
|
TSharedRef<SDockTab> SpawnTab_Viewport(const FSpawnTabArgs& Args);
|
||||||
|
TSharedRef<SDockTab> SpawnTab_Details(const FSpawnTabArgs& Args);
|
||||||
void RegisterTabSpawners(const TSharedRef<FTabManager>& InTabManager);
|
TSharedRef<SDockTab> SpawnTab_AssetBrowser(const FSpawnTabArgs& Args);
|
||||||
void UnregisterTabSpawners(const TSharedRef<FTabManager>& InTabManager);
|
TSharedRef<SDockTab> SpawnTab_MatrixEditor(const FSpawnTabArgs& Args);
|
||||||
|
TSharedRef<SDockTab> SpawnTab_GraphEditor(const FSpawnTabArgs& Args);
|
||||||
TSharedRef<SDockTab> SpawnTab_Viewport(const FSpawnTabArgs& Args);
|
TSharedRef<SDockTab> SpawnTab_Toolbar(const FSpawnTabArgs& Args);
|
||||||
TSharedRef<SDockTab> SpawnTab_Details(const FSpawnTabArgs& Args);
|
|
||||||
TSharedRef<SDockTab> SpawnTab_LayerSystem(const FSpawnTabArgs& Args);
|
// Create viewport widget
|
||||||
TSharedRef<SDockTab> SpawnTab_PhysicsSettings(const FSpawnTabArgs& Args);
|
TSharedRef<SWidget> CreateViewportWidget();
|
||||||
|
|
||||||
void PerformBooleanCut();
|
// Create details panel
|
||||||
void AddNewLayer();
|
TSharedRef<SWidget> CreateDetailsWidget();
|
||||||
void SaveEdits();
|
|
||||||
void PreviewEffects();
|
// Create asset browser
|
||||||
|
TSharedRef<SWidget> CreateAssetBrowserWidget();
|
||||||
private:
|
|
||||||
USkeletalMesh* SkeletalMesh;
|
// Create matrix editor
|
||||||
|
TSharedRef<SWidget> CreateMatrixEditorWidget();
|
||||||
TSharedPtr<SBorder> ViewportWidget;
|
|
||||||
TSharedPtr<IDetailsView> DetailsWidget;
|
// Create graph editor
|
||||||
TSharedPtr<SBorder> LayerSystemWidget;
|
TSharedRef<SWidget> CreateGraphEditorWidget();
|
||||||
TSharedPtr<SBorder> PhysicsSettingsWidget;
|
|
||||||
|
// Create toolbar
|
||||||
static const FName ViewportTabId;
|
TSharedRef<SWidget> CreateToolbarWidget();
|
||||||
static const FName DetailsTabId;
|
|
||||||
static const FName LayerSystemTabId;
|
// Create command list
|
||||||
static const FName PhysicsSettingsTabId;
|
void CreateCommandList();
|
||||||
|
|
||||||
|
// Generate bone tree row
|
||||||
|
TSharedRef<ITableRow> OnGenerateBoneRow(TSharedPtr<FBoneTreeItem> Item, const TSharedRef<STableViewBase>& OwnerTable);
|
||||||
|
|
||||||
|
// Get bone children
|
||||||
|
void OnGetBoneChildren(TSharedPtr<FBoneTreeItem> Item, TArray<TSharedPtr<FBoneTreeItem>>& OutChildren);
|
||||||
|
|
||||||
|
// Bone selection changed
|
||||||
|
void OnBoneSelectionChanged(TSharedPtr<FBoneTreeItem> Item, ESelectInfo::Type SelectInfo);
|
||||||
|
|
||||||
|
// Build bone hierarchy
|
||||||
|
void BuildBoneHierarchy();
|
||||||
|
|
||||||
|
// Build viscera node tree
|
||||||
|
void BuildVisceraNodeTree();
|
||||||
|
|
||||||
|
// Tree view generation methods
|
||||||
|
TSharedRef<ITableRow> OnGenerateNodeRow(TSharedPtr<FVisceraNodeItem> InItem, const TSharedRef<STableViewBase>& OwnerTable);
|
||||||
|
void OnGetNodeChildren(TSharedPtr<FVisceraNodeItem> InItem, TArray<TSharedPtr<FVisceraNodeItem>>& OutChildren);
|
||||||
|
void OnNodeSelectionChanged(TSharedPtr<FVisceraNodeItem> InItem, ESelectInfo::Type SelectInfo);
|
||||||
|
|
||||||
|
// Context menu for node tree
|
||||||
|
TSharedPtr<SWidget> OnGetNodeContextMenu(TSharedPtr<FVisceraNodeItem> InItem);
|
||||||
|
|
||||||
|
// Add new viscera node
|
||||||
|
void AddNewVisceraNode(const FString& NodeType, TSharedPtr<FVisceraNodeItem> ParentItem = nullptr);
|
||||||
|
|
||||||
|
// Command handlers
|
||||||
|
void OnOpenDismembermentGraphEditor();
|
||||||
|
void OnOpenAnatomicalLayerEditor();
|
||||||
|
void OnOpenBooleanCutTool();
|
||||||
|
void OnOpenBloodSystemEditor();
|
||||||
|
void OnImportCharacterModel();
|
||||||
|
void OnImportOrganModel();
|
||||||
|
void OnImportSkeletonModel();
|
||||||
|
void OnImportPhysicsAsset();
|
||||||
|
void OnTestMatrix();
|
||||||
|
void OnImportModel();
|
||||||
|
void OnSavePreset();
|
||||||
|
void OnLoadPreset();
|
||||||
|
|
||||||
|
// Viewport widget
|
||||||
|
TSharedPtr<class SViewport> ViewportWidget;
|
||||||
|
|
||||||
|
// Details panel
|
||||||
|
TSharedPtr<class IDetailsView> DetailsWidget;
|
||||||
|
|
||||||
|
// Asset browser
|
||||||
|
TSharedPtr<SAssetBrowser> AssetBrowserWidget;
|
||||||
|
|
||||||
|
// Matrix editor
|
||||||
|
TSharedPtr<SMatrixInputWidget> MatrixEditorWidget;
|
||||||
|
|
||||||
|
// Graph editor
|
||||||
|
TSharedPtr<SGraphEditor> GraphEditorWidget;
|
||||||
|
|
||||||
|
// Toolbar
|
||||||
|
TSharedPtr<class SBorder> ToolbarWidget;
|
||||||
|
|
||||||
|
// Bone tree view
|
||||||
|
TSharedPtr<STreeView<TSharedPtr<FBoneTreeItem>>> BoneTreeView;
|
||||||
|
|
||||||
|
// Node tree view
|
||||||
|
TSharedPtr<STreeView<TSharedPtr<FVisceraNodeItem>>> NodeTreeView;
|
||||||
|
|
||||||
|
// Bone items array
|
||||||
|
TArray<TSharedPtr<FBoneTreeItem>> BoneItems;
|
||||||
|
|
||||||
|
// Node items array
|
||||||
|
TArray<TSharedPtr<FVisceraNodeItem>> NodeItems;
|
||||||
|
|
||||||
|
// Cutting plane names
|
||||||
|
TArray<TSharedPtr<FName>> CuttingPlaneNames;
|
||||||
|
|
||||||
|
// Currently selected bone
|
||||||
|
TSharedPtr<FBoneTreeItem> SelectedBoneItem;
|
||||||
|
|
||||||
|
// Currently selected node
|
||||||
|
TSharedPtr<FVisceraNodeItem> SelectedNodeItem;
|
||||||
|
|
||||||
|
// Command list
|
||||||
|
TSharedPtr<FUICommandList> CommandList;
|
||||||
|
|
||||||
|
// Flag to track if the editor is initialized
|
||||||
|
bool bIsEditorInitialized;
|
||||||
|
|
||||||
|
// Viewport client
|
||||||
|
TSharedPtr<FFLESHViewportClient> ViewportClient;
|
||||||
|
|
||||||
|
// Scene viewport
|
||||||
|
TSharedPtr<FSceneViewport> Viewport;
|
||||||
|
|
||||||
|
// Viewport related methods
|
||||||
|
FReply OnResetCameraClicked();
|
||||||
|
FReply OnToggleWireframeClicked();
|
||||||
|
FReply OnToggleBonesClicked();
|
||||||
|
|
||||||
|
// The object being edited
|
||||||
|
UObject* EditingObject;
|
||||||
|
|
||||||
|
// Tab IDs
|
||||||
|
static const FName ViewportTabId;
|
||||||
|
static const FName DetailsTabId;
|
||||||
|
static const FName AssetBrowserTabId;
|
||||||
|
static const FName MatrixEditorTabId;
|
||||||
|
static const FName GraphEditorTabId;
|
||||||
|
static const FName ToolbarTabId;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user