Skip to content

Commit

Permalink
Merge pull request #42 from qiuwch/master
Browse files Browse the repository at this point in the history
Update UnrealCV to v0.3.0
  • Loading branch information
qiuwch committed Dec 16, 2016
2 parents a092bf9 + e4f3ddb commit 7e7aebd
Show file tree
Hide file tree
Showing 99 changed files with 2,575 additions and 836 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
Binaries/
Intermediate/
Config/
built/

*.ipynb_checkpoints/
core
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
install:
- pip install unrealcv
script:
script:
python test/test-unrealcv.py --travis
Binary file added Content/OpaqueMaterial.uasset
Binary file not shown.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
all:
python client/scripts/build-plugin.py --engine_path ${UnrealEngine} --dev
UE4Version=4.13
precompiled=unrealcv-$(shell python client/scripts/get-version.py)-$(UE4Version).zip
package:
# Package plugin to a zip file
rm -rf built/Intermediate
cd built && zip -r ../${precompiled} *

rebuild:
rm -rf built/
sh build.sh

clean:
rm -rf Intermediate/ Binaries/ built/
1 change: 1 addition & 0 deletions Source/ThirdParty/libprotobuf
Submodule libprotobuf added at 8d4239
21 changes: 3 additions & 18 deletions Source/UnrealCV/Private/CaptureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ void FCaptureManager::AttachGTCaptureComponentToCamera(APawn* Pawn)
SupportedModes.Add(TEXT("depth"));
SupportedModes.Add(TEXT("debug"));
SupportedModes.Add(TEXT("object_mask"));
SupportedModes.Add(TEXT("normal"));
SupportedModes.Add(TEXT("normal"));
SupportedModes.Add(TEXT("wireframe"));
SupportedModes.Add(TEXT("default"));
SupportedModes.Add(TEXT("default"));
// TODO: Get the list from GTCaptureComponent

CaptureComponentList.Empty();
Expand All @@ -30,21 +30,6 @@ void FCaptureManager::AttachGTCaptureComponentToCamera(APawn* Pawn)
CaptureComponentList.Add(RightEye);
}

APawn* GetFirstPawn()
{
static UWorld* CurrentWorld = nullptr;
static APawn* Pawn = nullptr;
if (Pawn == nullptr || CurrentWorld != GWorld)
{
APlayerController* PlayerController = GWorld->GetFirstPlayerController();
check(PlayerController);
Pawn = PlayerController->GetPawn();
check(Pawn);
CurrentWorld = GWorld;
}
return Pawn;
}

UGTCaptureComponent* FCaptureManager::GetCamera(int32 CameraId)
{
if (CameraId < CaptureComponentList.Num() && CameraId >= 0)
Expand All @@ -55,4 +40,4 @@ UGTCaptureComponent* FCaptureManager::GetCamera(int32 CameraId)
{
return nullptr;
}
}
}
18 changes: 9 additions & 9 deletions Source/UnrealCV/Private/CommandDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class FAsyncWatcher : public FRunnable
Thread = FRunnableThread::Create(this, TEXT("FAsyncWatcher"), 8 * 1024, TPri_Normal);
Stopping = false;
}
TQueue<FPromise, EQueueMode::Spsc> PendingPromise;
TQueue<FCallbackDelegate, EQueueMode::Spsc> PendingCompletedCallback;

TQueue<FPromise, EQueueMode::Spsc> PendingPromise;
TQueue<FCallbackDelegate, EQueueMode::Spsc> PendingCompletedCallback;
bool Stopping; // Whether this thread should stop?

FRunnableThread* Thread;
virtual uint32 Run() override
{
while (!Stopping)
while (!Stopping)
{
while (IsActive())
{
Expand Down Expand Up @@ -253,7 +253,7 @@ void FCommandDispatcher::ExecAsync(const FString Uri, const FCallbackDelegate Ca
FExecStatus ExecStatus = Exec(Uri);
if (ExecStatus == FExecStatusType::AsyncQuery) // This is an async task
{
FAsyncWatcher::Get().Wait(ExecStatus.GetPromise(), Callback);
FAsyncWatcher::Get().Wait(ExecStatus.GetPromise(), Callback);
}
else
{
Expand All @@ -262,7 +262,7 @@ void FCommandDispatcher::ExecAsync(const FString Uri, const FCallbackDelegate Ca
}
}


FExecStatus FCommandDispatcher::Exec(const FString Uri)
{
check(IsInGameThread());
Expand All @@ -280,20 +280,20 @@ FExecStatus FCommandDispatcher::Exec(const FString Uri)

// FDispatcherDelegate& Cmd = Elem.Value;
FDispatcherDelegate& Cmd = UriMapping[Key];

FRegexMatcher Matcher(Pattern, Uri);
if (Matcher.FindNext())
{
for (uint32 GroupIndex = 1; GroupIndex < NumArgsLimit + 1; GroupIndex++)
{
{
uint32 BeginIndex = Matcher.GetCaptureGroupBeginning(GroupIndex);
if (BeginIndex == -1) break; // No more matching group to extract
FString Match = Matcher.GetCaptureGroup(GroupIndex); // TODO: Strip empty space
Args.Add(Match);
}
return Cmd.Execute(Args); // The exec status can be successful, fail or give a message back
}

// TODO: Regular expression mapping is slow, need to implement in a more efficient way.
// FRegexMatcher()
}
Expand Down
25 changes: 25 additions & 0 deletions Source/UnrealCV/Private/Commands/ActionHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "UnrealCVPrivate.h"
#include "ActionHandler.h"

void FActionCommandHandler::RegisterCommands()
{
FDispatcherDelegate Cmd;
FString Help;

Cmd = FDispatcherDelegate::CreateRaw(this, &FActionCommandHandler::PauseGame);
Help = "Pause the game";
CommandDispatcher->BindCommand("vset /action/game/pause", Cmd, Help);

/*
Cmd = FDispatcherDelegate::CreateRaw(this, &FActionCommandHandler::ResumeGame);
Help = "Resume the game";
CommandDispatcher->BindCommand("vset /action/game/resume", Cmd, Help);
*/
}

FExecStatus FActionCommandHandler::PauseGame(const TArray<FString>& Args)
{
APlayerController* PlayerController = GWorld->GetFirstPlayerController();
PlayerController->Pause();
return FExecStatus::OK();
}
16 changes: 16 additions & 0 deletions Source/UnrealCV/Private/Commands/ActionHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "CommandHandler.h"

class FActionCommandHandler : public FCommandHandler
{
public:
FActionCommandHandler(FCommandDispatcher* InCommandDispatcher) : FCommandHandler(InCommandDispatcher)
{}
void RegisterCommands();

/** vset /action/game/pause */
FExecStatus PauseGame(const TArray<FString>& Args);

/** vset /action/game/resume */
FExecStatus ResumeGame(const TArray<FString>& Args);
};
32 changes: 32 additions & 0 deletions Source/UnrealCV/Private/Commands/AliasHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "UnrealCVPrivate.h"
#include "AliasHandler.h"

void FAliasCommandHandler::RegisterCommands()
{
FDispatcherDelegate Cmd;
FString Help;

Cmd = FDispatcherDelegate::CreateRaw(this, &FAliasCommandHandler::VRun);
Help = "Run UE4 built-in commands";
CommandDispatcher->BindCommand("vrun [str]", Cmd, Help);
CommandDispatcher->BindCommand("vrun [str] [str]", Cmd, Help);
CommandDispatcher->BindCommand("vrun [str] [str] [str]", Cmd, Help);
}

FExecStatus FAliasCommandHandler::VRun(const TArray<FString>& Args)
{
FString Cmd = "";

uint32 NumArgs = Args.Num();
for (uint32 ArgIndex = 0; ArgIndex < NumArgs-1; ArgIndex++)
{
Cmd += Args[ArgIndex] + " ";
}
Cmd += Args[NumArgs-1];
UWorld* World = FUE4CVServer::Get().GetGameWorld();
check(World->IsGameWorld());

APlayerController* PlayerController = World->GetFirstPlayerController();
PlayerController->ConsoleCommand(Cmd, true);
return FExecStatus::OK();
}
13 changes: 13 additions & 0 deletions Source/UnrealCV/Private/Commands/AliasHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "CommandHandler.h"

class FAliasCommandHandler : public FCommandHandler
{
public:
FAliasCommandHandler(FCommandDispatcher* InCommandDispatcher) : FCommandHandler(InCommandDispatcher)
{}
void RegisterCommands();

/** vrun * */
FExecStatus VRun(const TArray<FString>& Args);
};
60 changes: 49 additions & 11 deletions Source/UnrealCV/Private/Commands/CameraHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "PlayerViewMode.h"
#include "UE4CVServer.h"
#include "CaptureManager.h"
#include "CineCameraActor.h"

FString GetDiskFilename(FString Filename)
{
Expand All @@ -31,7 +32,7 @@ void FCameraCommandHandler::RegisterCommands()
{
FDispatcherDelegate Cmd;
FString Help;

Cmd = FDispatcherDelegate::CreateRaw(this, &FCameraCommandHandler::GetCameraViewMode);
CommandDispatcher->BindCommand("vget /camera/[uint]/[str]", Cmd, "Get snapshot from camera, the third parameter is optional"); // Take a screenshot and return filename

Expand Down Expand Up @@ -158,10 +159,28 @@ FExecStatus FCameraCommandHandler::GetCameraRotation(const TArray<FString>& Args
{
if (Args.Num() == 1)
{
int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
// FRotator CameraRotation = this->Character->GetActorRotation(); // We need the rotation of the controller
APawn* Pawn = FUE4CVServer::Get().GetPawn();
FRotator CameraRotation = Pawn->GetControlRotation();
bool bIsMatinee = false;

FRotator CameraRotation;
ACineCameraActor* CineCameraActor = nullptr;
for (AActor* Actor : GWorld->GetCurrentLevel()->Actors)
{
// if (Actor && Actor->IsA(AMatineeActor::StaticClass())) // AMatineeActor is deprecated
if (Actor && Actor->IsA(ACineCameraActor::StaticClass()))
{
bIsMatinee = true;
CameraRotation = Actor->GetActorRotation();
break;
}
}

if (!bIsMatinee)
{
int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
APawn* Pawn = FUE4CVServer::Get().GetPawn();
CameraRotation = Pawn->GetControlRotation();
}

FString Message = FString::Printf(TEXT("%.3f %.3f %.3f"), CameraRotation.Pitch, CameraRotation.Yaw, CameraRotation.Roll);

return FExecStatus::OK(Message);
Expand All @@ -173,9 +192,28 @@ FExecStatus FCameraCommandHandler::GetCameraLocation(const TArray<FString>& Args
{
if (Args.Num() == 1)
{
int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
APawn* Pawn = FUE4CVServer::Get().GetPawn();
FVector CameraLocation = Pawn->GetActorLocation();
bool bIsMatinee = false;

FVector CameraLocation;
ACineCameraActor* CineCameraActor = nullptr;
for (AActor* Actor : GWorld->GetCurrentLevel()->Actors)
{
// if (Actor && Actor->IsA(AMatineeActor::StaticClass())) // AMatineeActor is deprecated
if (Actor && Actor->IsA(ACineCameraActor::StaticClass()))
{
bIsMatinee = true;
CameraLocation = Actor->GetActorLocation();
break;
}
}

if (!bIsMatinee)
{
int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
APawn* Pawn = FUE4CVServer::Get().GetPawn();
CameraLocation = Pawn->GetActorLocation();
}

FString Message = FString::Printf(TEXT("%.3f %.3f %.3f"), CameraLocation.X, CameraLocation.Y, CameraLocation.Z);

return FExecStatus::OK(Message);
Expand Down Expand Up @@ -257,7 +295,7 @@ FExecStatus FCameraCommandHandler::GetCameraViewMode(const TArray<FString>& Args
}
});
FString Message = FString::Printf(TEXT("File will be saved to %s"), *Filename);
return FExecStatus::AsyncQuery(FPromise(PromiseDelegate), Message);
return FExecStatus::AsyncQuery(FPromise(PromiseDelegate), Message);
// The filename here is just for message, not the fullname on the disk, because we can not know that due to sandbox issue.
}
return FExecStatus::InvalidArgument;
Expand All @@ -279,8 +317,8 @@ FExecStatus FCameraCommandHandler::GetScreenshot(const TArray<FString>& Args)
Filename = Args[1];
}

FString FullFilename = GetDiskFilename(Filename);
return FScreenCapture::GetCameraViewAsyncQuery(FullFilename);
// FString FullFilename = GetDiskFilename(Filename);
return FScreenCapture::GetCameraViewAsyncQuery(Filename);
}
return FExecStatus::InvalidArgument;
}
Expand Down
12 changes: 6 additions & 6 deletions Source/UnrealCV/Private/Commands/ObjectHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ void FObjectCommandHandler::RegisterCommands()
Cmd = FDispatcherDelegate::CreateRaw(this, &FObjectCommandHandler::GetObjectName);
Help = "[debug] Get the object name";
CommandDispatcher->BindCommand(TEXT("vget /object/[str]/name"), Cmd, Help);

Cmd = FDispatcherDelegate::CreateRaw(this, &FObjectCommandHandler::GetObjectLocation);
Help = "Get object location [x, y, z]";
CommandDispatcher->BindCommand(TEXT("vget /object/[str]/location"), Cmd, Help);

Cmd = FDispatcherDelegate::CreateRaw(this, &FObjectCommandHandler::GetObjectRotation);
Help = "Get object rotation [pitch, yaw, roll]";
CommandDispatcher->BindCommand(TEXT("vget /object/[str]/rotation"), Cmd, Help);

Cmd = FDispatcherDelegate::CreateRaw(this, &FObjectCommandHandler::SetObjectLocation);
Help = "Set object location [x, y, z]";
CommandDispatcher->BindCommand(TEXT("vset /object/[str]/location [float] [float] [float]"), Cmd, Help);

Cmd = FDispatcherDelegate::CreateRaw(this, &FObjectCommandHandler::SetObjectRotation);
Help = "Set object rotation [pitch, yaw, roll]";
CommandDispatcher->BindCommand(TEXT("vset /object/[str]/rotation [float] [float] [float]"), Cmd, Help);
Expand Down Expand Up @@ -198,9 +198,9 @@ FExecStatus FObjectCommandHandler::SetObjectLocation(const TArray<FString>& Args

// TODO: Check whether this object is movable
float X = FCString::Atof(*Args[1]), Y = FCString::Atof(*Args[2]), Z = FCString::Atof(*Args[3]);
FVector NewLocation = FVector(X, Y, Z);
FVector NewLocation = FVector(X, Y, Z);
bool Success = Object->SetActorLocation(NewLocation);

return FExecStatus::OK();
}
return FExecStatus::InvalidArgument;
Expand Down
8 changes: 4 additions & 4 deletions Source/UnrealCV/Private/Commands/ObjectHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class FObjectCommandHandler : public FCommandHandler

/** Get object location */
FExecStatus GetObjectLocation(const TArray<FString>& Args);

/** Get object rotation */
FExecStatus GetObjectRotation(const TArray<FString>& Args);

/** Set object location */
FExecStatus SetObjectLocation(const TArray<FString>& Args);

/** Set object rotation */
FExecStatus SetObjectRotation(const TArray<FString>& Args);
FExecStatus SetObjectRotation(const TArray<FString>& Args);
};

0 comments on commit 7e7aebd

Please sign in to comment.