Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/grab-mode #2

Merged
merged 23 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1ca1e56
Add ClickDragMode and AddForceMode that is activated from top menu or…
AlgoryxJosef Oct 7, 2024
a0622bf
Debug render line and scale force with distance squared
AlgoryxJosef Oct 7, 2024
0d39017
Allow camera move etc in the mode
AlgoryxJosef Oct 7, 2024
66d73af
Lower force scaling
AlgoryxJosef Oct 8, 2024
a2b16ef
Use Lock Constrraint instead of AddForce
AlgoryxJosef Oct 8, 2024
f97953e
Merge branch 'feature/target-agx-2.39' into hackathon/viewport-intera…
AlgoryxJosef Nov 22, 2024
ed82186
Rename to ForcePickingMode and add an eject command on activate
AlgoryxJosef Nov 22, 2024
15b7575
Rename force picking -> grab
AlgoryxJosef Nov 22, 2024
2b8b5d8
Merge branch 'master' into hackathon/viewport-interaction
AlgoryxJosef Nov 26, 2024
028eb89
Merge branch 'master' into hackathon/viewport-interaction
AlgoryxJosef Nov 28, 2024
fee316d
Minor fixes in texts/edits
AlgoryxJosef Nov 28, 2024
0fe718e
Fix cursor
AlgoryxJosef Nov 28, 2024
d483956
Fix attach detach logic
AlgoryxJosef Nov 28, 2024
44d284c
Setup keyboard shortcut
AlgoryxJosef Nov 28, 2024
5502b97
Add user manual info
AlgoryxJosef Nov 28, 2024
423781a
Remove the agx icon from the top menu entry
AlgoryxJosef Nov 28, 2024
abbafb6
Add grab hand icon
AlgoryxJosef Dec 4, 2024
ac75150
Update icon
AlgoryxJosef Dec 5, 2024
8c5f431
Add missing includes
AlgoryxJosef Dec 5, 2024
525f9b8
Add gitignore
AlgoryxJosef Dec 6, 2024
b7b80f3
Simplify SetComplience calls and remove Activation from AGXEdMode
AlgoryxJosef Dec 17, 2024
faeeb69
Put LostFocus function in the right place in the header
AlgoryxJosef Dec 17, 2024
9056cee
Forward declare RigidBodyComponent
AlgoryxJosef Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/Content/Terrain/TerrainMaterialLibrary
/Content/Shape/ContactMaterialLibrary
/Content/Shape/ShapeMaterialLibrary
/Content/Sensor/Lidar/AmbientMaterialLibrary
/license/agx.lic
/Source/AGXUnreal/Public/AGX_BuildInfo.h
/Source/ThirdParty/agx
/Source/AGXUnrealBarrier/Public/AGX_BuildInfo.generated.h
Binaries
DerivedDataCache
Intermediate
Binary file added Content/Editor/Icons/grab_32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions Source/AGXUnreal/Public/AGX_Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Containers/Map.h"
#include "CoreMinimal.h"
#include "Engine/EngineTypes.h"
#include "Framework/Commands/InputChord.h"
#include "Misc/EngineVersionComparison.h"
#include "Subsystems/GameInstanceSubsystem.h"

Expand Down Expand Up @@ -247,7 +248,6 @@ class AGXUNREAL_API UAGX_Simulation : public UGameInstanceSubsystem
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category = "AGX Lidar")
int32 RaytraceDeviceIndex {0};


#if WITH_EDITORONLY_DATA
/**
* Set to true to write an AGX Dynamics for Unreal archive of the initial state.
Expand Down Expand Up @@ -343,9 +343,17 @@ class AGXUNREAL_API UAGX_Simulation : public UGameInstanceSubsystem
* Whether or not to override each AGX Shape with the selected AdditionalUnrealCollision
* setting. If this is set to false, the setting on each AGX Shape is used instead.
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Other")
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category = "Other")
bool bOverrideAdditionalUnrealCollision {false};

/**
* Keyboard shortcut to enable Grab Mode, making it possible to grab a Rigid Body in the
* viewport with the mouse.
* Note: if changed, the Unreal Editor must be restarted for the change to take effect.
AlgoryxMartinN marked this conversation as resolved.
Show resolved Hide resolved
*/
UPROPERTY(Config, EditAnywhere, Category = "Other")
FInputChord GrabModeKeyboardShortcut {EKeys::Insert};

/**
* Additional Unreal Collision Geometry to use for all AGX Shapes.
* Does not affect AGX Dynamics, but can be used to get support for e.g. LineTrace (Query) or
Expand All @@ -355,7 +363,7 @@ class AGXUNREAL_API UAGX_Simulation : public UGameInstanceSubsystem
* true, otherwise the AdditionalUnrealCollision setting belonging to each AGX Shape is used.
*/
UPROPERTY(
EditAnywhere, BlueprintReadOnly, Category = "Other",
Config, EditAnywhere, BlueprintReadOnly, Category = "Other",
Meta = (EditCondition = "bOverrideAdditionalUnrealCollision"))
TEnumAsByte<enum ECollisionEnabled::Type> AdditionalUnrealCollision {
ECollisionEnabled::QueryOnly};
Expand Down
70 changes: 68 additions & 2 deletions Source/AGXUnrealEditor/Private/AGXUnrealEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "AssetToolsModule.h"
#include "AssetTypeCategories.h"
#include "Editor/UnrealEdEngine.h"
#include "Framework/Commands/Commands.h"
#include "IAssetTools.h"
#include "IAssetTypeActions.h"
#include "IPlacementModeModule.h"
#include "ISettingsModule.h"
#include "LevelEditor.h"
#include "Modules/ModuleManager.h"
#include "PropertyEditorModule.h"
#include "UnrealEdGlobals.h"
Expand All @@ -27,6 +29,7 @@
#include "AGX_RigidBodyReference.h"
#include "AGX_Real.h"
#include "AGX_RealDetails.h"
#include "AGX_RuntimeStyle.h"
#include "AGX_ModelSourceComponent.h"
#include "AGX_ModelSourceComponentCustomization.h"
#include "AGX_Simulation.h"
Expand All @@ -41,6 +44,7 @@
#include "AgxEdMode/AGX_AgxEdModeFileCustomization.h"
#include "AgxEdMode/AGX_AgxEdModeTerrain.h"
#include "AgxEdMode/AGX_AgxEdModeTerrainCustomization.h"
#include "AgxEdMode/AGX_GrabMode.h"
#include "AMOR/AGX_ConstraintMergeSplitThresholdsTypeActions.h"
#include "AMOR/AGX_ShapeContactMergeSplitThresholdsTypeActions.h"
#include "AMOR/AGX_WireMergeSplitThresholdsTypeActions.h"
Expand Down Expand Up @@ -110,6 +114,7 @@
#include "Tires/AGX_TwoBodyTireComponent.h"
#include "Tires/AGX_TwoBodyTireActor.h"
#include "Tires/AGX_TwoBodyTireComponentCustomization.h"
#include "Utilities/AGX_EditorUtilities.h"
#include "Vehicle/AGX_TrackComponent.h"
#include "Vehicle/AGX_TrackComponentDetails.h"
#include "Vehicle/AGX_TrackComponentVisualizer.h"
Expand All @@ -128,6 +133,37 @@

#define LOCTEXT_NAMESPACE "FAGXUnrealEditorModule"

class FAGX_GlobalKeyboardCommands : public TCommands<FAGX_GlobalKeyboardCommands>
{
public:
FAGX_GlobalKeyboardCommands()
: TCommands<FAGX_GlobalKeyboardCommands>(
TEXT("FAGXUnrealEditorModule"), LOCTEXT("FAGXUnrealEditorModule", "AGX UE Editor"),
NAME_None, FAGX_RuntimeStyle::GetStyleSetName())
{
}

virtual void RegisterCommands() override
{
auto Sim = Cast<UAGX_Simulation>(UAGX_Simulation::StaticClass()->GetDefaultObject());
if (Sim == nullptr)
{
UE_LOG(
LogAGX, Warning,
TEXT("RegisterCommands failed in AGXUnrealEditor, could not get the AGX Simulation "
"CDO. Keyboard commands may not work as expected."));
return;
}

UI_COMMAND(
ActivateGrabCommand, "Activate AGX Grab", "Activate AGX Grab",
EUserInterfaceActionType::Button, Sim->GrabModeKeyboardShortcut);
}

public:
TSharedPtr<FUICommandInfo> ActivateGrabCommand;
};

void FAGXUnrealEditorModule::StartupModule()
{
FAGX_EditorStyle::Initialize();
Expand Down Expand Up @@ -189,12 +225,26 @@ void FAGXUnrealEditorModule::UnregisterProjectSettings()

void FAGXUnrealEditorModule::RegisterCommands()
{
// Nothing here yet.
FAGX_GlobalKeyboardCommands::Register();

FLevelEditorModule& LevelEditorModule =
FModuleManager::GetModuleChecked<FLevelEditorModule>(TEXT("LevelEditor"));

const auto GrabModeCommands = FAGX_GlobalKeyboardCommands::Get();
if (!LevelEditorModule.GetGlobalLevelEditorActions()->IsActionMapped(
GrabModeCommands.ActivateGrabCommand))
{
LevelEditorModule.GetGlobalLevelEditorActions()->MapAction(
GrabModeCommands.ActivateGrabCommand,
FExecuteAction::CreateRaw(this, &FAGXUnrealEditorModule::OnGrabModeCommand),
FCanExecuteAction::CreateRaw(
this, &FAGXUnrealEditorModule::OnCanExecuteGrabModeCommand));
}
}

void FAGXUnrealEditorModule::UnregisterCommands()
{
// Nothing here yet.
FAGX_GlobalKeyboardCommands::Unregister();
}

void FAGXUnrealEditorModule::RegisterAssetTypeActions()
Expand Down Expand Up @@ -632,11 +682,16 @@ void FAGXUnrealEditorModule::RegisterModes()
FAGX_EditorStyle::GetStyleSetName(), FAGX_EditorStyle::AgxIcon,
FAGX_EditorStyle::AgxIconSmall),
/*bVisisble*/ true);

FEditorModeRegistry::Get().RegisterMode<FAGX_GrabMode>(
FAGX_GrabMode::EM_AGX_GrabModeId, LOCTEXT("AGXGrabMode", "Grab Mode"), FSlateIcon(),
/*bVisisble*/ false);
}

void FAGXUnrealEditorModule::UnregisterModes()
{
FEditorModeRegistry::Get().UnregisterMode(FAGX_AgxEdMode::EM_AGX_AgxEdModeId);
FEditorModeRegistry::Get().UnregisterMode(FAGX_GrabMode::EM_AGX_GrabModeId);
}

void FAGXUnrealEditorModule::RegisterPlacementCategory()
Expand Down Expand Up @@ -693,6 +748,17 @@ void FAGXUnrealEditorModule::InitializeAssets()
AGX_MaterialLibrary::InitializeLidarAmbientMaterialAssetLibrary();
}

void FAGXUnrealEditorModule::OnGrabModeCommand() const
{
FAGX_GrabMode::Activate();
}
AlgoryxMartinN marked this conversation as resolved.
Show resolved Hide resolved

bool FAGXUnrealEditorModule::OnCanExecuteGrabModeCommand() const
{
const UWorld* World = FAGX_EditorUtilities::GetCurrentWorld();
return World != nullptr && World->IsGameWorld();
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FAGXUnrealEditorModule, AGXUnrealEditor);
10 changes: 7 additions & 3 deletions Source/AGXUnrealEditor/Private/AGX_EditorStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ TSharedPtr<FSlateStyleSet> FAGX_EditorStyle::StyleInstance = nullptr;
const FName FAGX_EditorStyle::AgxIcon("AgxIcon");
const FName FAGX_EditorStyle::AgxIconSmall("AgxIcon.Small");
const FName FAGX_EditorStyle::AgxIconTiny("AgxIcon.Tiny");
const FName FAGX_EditorStyle::JointIcon("JointIcon");
const FName FAGX_EditorStyle::JointIconSmall("JointIcon.Small");
const FName FAGX_EditorStyle::GrabIcon("GrabIcon");
const FName FAGX_EditorStyle::FileIcon("FileIcon");
const FName FAGX_EditorStyle::FileIconSmall("FileIcon.Small");
const FName FAGX_EditorStyle::JointIcon("JointIcon");
const FName FAGX_EditorStyle::JointIconSmall("JointIcon.Small");
const FName FAGX_EditorStyle::LicenseKeyIcon("LicenseKey");
const FName FAGX_EditorStyle::TerrainIcon("TerrainIcon");
const FName FAGX_EditorStyle::TerrainIconSmall("TerrainIcon.Small");
const FName FAGX_EditorStyle::LicenseKeyIcon("LicenseKey");



void FAGX_EditorStyle::Initialize()
{
Expand Down Expand Up @@ -99,6 +102,7 @@ TSharedRef<class FSlateStyleSet> FAGX_EditorStyle::Create()
Style->Set(TerrainIcon, new IMAGE_BRUSH("Icons/Terrain_64x64", IconSize64));
Style->Set(TerrainIconSmall, new IMAGE_BRUSH("Icons/Terrain_32x32", IconSize32));
Style->Set(LicenseKeyIcon, new IMAGE_BRUSH("Icons/license_key_16x16", IconSize16));
Style->Set(GrabIcon, new IMAGE_BRUSH("Icons/grab_32x32", IconSize16));
AlgoryxMartinN marked this conversation as resolved.
Show resolved Hide resolved

// Component icons, visible in the Components list/hierarchy of an Actor and in the Add
// Component dialog / list. Bodies.
Expand Down
53 changes: 53 additions & 0 deletions Source/AGXUnrealEditor/Private/AGX_TopMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "AGX_LogCategory.h"
#include "AGX_RigidBodyComponent.h"
#include "AgxEdMode/AGX_AgxEdModeFile.h"
#include "AgxEdMode/AGX_GrabMode.h"
#include "AGXUnrealEditor.h"
#include "Constraints/AGX_ConstraintComponent.h"
#include "Constraints/AGX_BallConstraintActor.h"
Expand Down Expand Up @@ -196,6 +197,21 @@ FAGX_TopMenu::~FAGX_TopMenu()

Builder.AddMenuSeparator();

{
const FSlateIcon GrabIcon(
FAGX_EditorStyle::GetStyleSetName(), FAGX_EditorStyle::GrabIcon,
FAGX_EditorStyle::GrabIcon);
Builder.AddSubMenu(
LOCTEXT("GrabModeMenuLabel", "Grab Mode"),
LOCTEXT(
"GrabModeMenuTooltip",
"Activate/Deactivate the Grab mode, making it possible to grab a "
"Rigid Body in the Level by clicking and dragging the mouse in the viewport."),
FNewMenuDelegate::CreateRaw(this, &FAGX_TopMenu::FillGrabModeMenu), false, GrabIcon);
}

Builder.AddMenuSeparator();

{
const FSlateIcon AgxIcon(
FAGX_EditorStyle::GetStyleSetName(), FAGX_EditorStyle::AgxIconSmall,
Expand Down Expand Up @@ -332,6 +348,22 @@ void FAGX_TopMenu::FillLicenseMenu(FMenuBuilder& Builder)
[&]() { FAGX_TopMenu::OnOpenGenerateRuntimeActivationDialogClicked(); });
}

void FAGX_TopMenu::FillGrabModeMenu(FMenuBuilder& Builder)
{
AddFileMenuEntry(
Builder, LOCTEXT("StartGrabModeMenuLabel", "Start"),
LOCTEXT(
"StartGrabModeMenuLabelToolTip",
"Activate the Grab mode, making it possible to grab a "
"Rigid Body in the Level by clicking and dragging the mouse in the viewport."),
[&]() { FAGX_TopMenu::OnStartGrabModeDialogClicked(); });

AddFileMenuEntry(
Builder, LOCTEXT("StopGrabModeMenuLabel", "Stop"),
LOCTEXT("StopGrabModeMenuLabelToolTip", "Deactivate the Grab mode."),
[&]() { FAGX_TopMenu::OnStopGrabModeDialogClicked(); });
}

void FAGX_TopMenu::OnCreateConstraintClicked(UClass* ConstraintClass)
{
AActor* Actor1 = nullptr;
Expand Down Expand Up @@ -490,4 +522,25 @@ void FAGX_TopMenu::OnOpenGenerateRuntimeActivationDialogClicked()
FSlateApplication::Get().AddModalWindow(Window, nullptr);
}

void FAGX_TopMenu::OnStartGrabModeDialogClicked()
{
UWorld* World = FAGX_EditorUtilities::GetCurrentWorld();
if (World == nullptr)
return;

if (!World->IsGameWorld())
{
FAGX_NotificationUtilities::ShowDialogBoxWithErrorLog(
"Grab mode if only supported during play.");
return;
}

FAGX_GrabMode::Activate();
}

void FAGX_TopMenu::OnStopGrabModeDialogClicked()
{
FAGX_GrabMode::Deactivate();
}

#undef LOCTEXT_NAMESPACE
1 change: 1 addition & 0 deletions Source/AGXUnrealEditor/Private/AgxEdMode/AGX_AgxEdMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "AgxEdMode/AGX_AgxEdModeTerrain.h"
#include "AgxEdMode/AGX_AgxEdModeToolkit.h"
#include "Toolkits/ToolkitManager.h"
#include "Utilities/AGX_EditorUtilities.h"

// Unreal Engine includes.
#include "EditorModeManager.h"
Expand Down
Loading