Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/unrealcv/unrealcv into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
qiuwch committed Jun 26, 2017
2 parents 0ef22d0 + a8eda13 commit b4ffa48
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
20 changes: 14 additions & 6 deletions client/python/unrealcv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def ReceivePayload(cls, socket):

rfile.close()

return payload.decode('UTF-8')
return payload

@classmethod
def WrapAndSendPayload(cls, socket, payload):
Expand Down Expand Up @@ -116,6 +116,7 @@ def WrapAndSendPayload(cls, socket, payload):
_L.error('Fail to send message %s', e)
return False


class BaseClient(object):
'''
BaseClient send message out and receiving message in a seperate thread.
Expand Down Expand Up @@ -171,7 +172,7 @@ def connect(self, timeout = 1):
self.socket = None

def isconnected(self):
return self.socket != None
return self.socket is not None

def disconnect(self):
if self.isconnected():
Expand All @@ -191,7 +192,7 @@ def __receiving(self):
Also check whether client is still connected
'''
_L.debug('BaseClient start receiving in %s', threading.current_thread().name)
while (1):
while True:
if self.isconnected():
# Only this thread is allowed to read from socket, otherwise need lock to avoid competing
message = SocketMessage.ReceivePayload(self.socket)
Expand All @@ -201,8 +202,8 @@ def __receiving(self):
self.socket = None
continue

if message.startswith('connected'):
_L.info('Got connection confirm: %s', repr(message))
if message.startswith(b'connected'):
_L.info('Got connection confirm: %s', repr(message.decode('utf-8')))
self.wait_connected.set()
# self.wait_connected.clear()
continue
Expand All @@ -224,6 +225,7 @@ def send(self, message):
_L.error('Fail to send message, client is not connected')
return False


class Client(object):
'''
Client can be used to send request to a game and get response
Expand All @@ -233,9 +235,15 @@ class Client(object):
def __raw_message_handler(self, raw_message):
# print 'Waiting for message id %d' % self.message_id
match = self.raw_message_regexp.match(raw_message)

if match:
[message_id, message_body] = (int(match.group(1)), match.group(2)) # TODO: handle multiline response
message_body = raw_message[len(match.group(1))+1:]
# Convert to utf-8 if it's not a byte array (as is the case for images)
try:
message_body = message_body.decode('utf-8')
except UnicodeDecodeError:
pass
# print 'Received message id %s' % message_id
if message_id == self.message_id:
self.response = message_body
Expand All @@ -252,7 +260,7 @@ def do_callback():
_L.error('No message handler to handle message %s', raw_message)

def __init__(self, endpoint, message_handler=None):
self.raw_message_regexp = re.compile('(\d{1,8}):(.*)')
self.raw_message_regexp = re.compile(b'(\d{1,8}):(.*)')
self.message_client = BaseClient(endpoint, self.__raw_message_handler)
self.message_handler = message_handler
self.message_id = 0
Expand Down
44 changes: 43 additions & 1 deletion docs/plugin/develop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ Linux
Mac

- Install Xcode.

- To generate Xcode Project, right click :file:`playground.uproject` and choose :code:`Service->Generate Xcode Project`.

- Open the :file:`*.xcworkspace` file and build. The plugin code will be compiled together with the game project.

.. note::

Need help for writing this section
Please make sure that you have installed the UnrealCV plugin to Unreal Engine. If you wish to install the plugin in the project, please install the plugin in the project before you generate Xcode Project. To switch the version, you can right click :file:`playground.uproject` and choose :code:`Service->Switch Unreal Engine Version`.


Useful resources for development include:
Expand All @@ -86,6 +92,42 @@ The benefit of implementing an UnrealCV command are:
1. You can use the communication protocol provided by UnrealCV to exchange data between your program and UE4.
2. You can share your code with other researchers, so that it can be used by others.

First we go through a very simple example which prints a message. Assume that we want to add a commamd :code:`vget /object/helloworld` to print "Hello World!". We need to modify two files: :file:`ObjectHandler.h` and :file:`ObjectHandler.cpp`.

In :file:`ObjectHandler.h`, we need to add a member function:

.. code:: c
   FExecStatus HelloWorld(const TArray<FString>& Args);
In :file:`ObjectHandler.cpp`, we define this member function:

.. code:: c
   FExecStatus FObjectCommandHandler::HelloWorld(const TArray<FString>& Args)
{
FString Msg;
Msg += "Hello World!";
return FExecStatus::OK(Msg);
}
Then we need to bind the command with the function:

.. code:: c
void FObjectCommandHandler::RegisterCommands()
{
...
Cmd = FDispatcherDelegate::CreateRaw(this, &FObjectCommandHandler::HelloWorld);
Help = "Print Hello World";
CommandDispatcher->BindCommand(TEXT("vget /object/helloworld"), Cmd, Help);
...
}
After the modification, we can compile and use the new command.

Here we will walk you through how to implement a command :code:`vset /object/[id]/rotation` to enable you set the rotation of an object.

:code:`FExecStatus` return the exec result of this command. The result will be returned as a text string.
Expand Down
8 changes: 7 additions & 1 deletion docs/plugin/editor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
Usage in the Editor
======================

In UE4 editor, you can edit the scene and change the material properties. We show a few examples here using the scene
In UE4 editor, you can run UnrealCV command, edit the scene and change the material properties. We show a few examples here using the scene
`RealisticRendering <http://docs.unrealcv.org/en/develop/reference/model_zoo.html#realisticrendering>`_.

Run UnrealCV Command
--------------------

While playing the level in the editor, press ` to open the built-in console and run UnrealCV like in the game binary.

.. image:: https://image.ibb.co/jog255/command1.png

Edit Object Specularity
-----------------------
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/contact.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ Team Members

UnrealCV is developed and maintained by a group of students working on computer vision (sort alphabetically).

- `Fangwei Zhong`
- `Siyuan Qiao <http://www.cs.jhu.edu/~syqiao/>`_: Stochastic virtual scene generation
- `Tae Soo Kim`: Deep learning for transferable concepts between the real and the virtual environment
- `Weichao Qiu <http://weichaoqiu.com>`_: Constructing virtual worlds to train and diagnose computer vision algorithms
- `Yi Zhang`: Algorithm diagnosis with synthetic data
- `Fangwei Zhong`
- `Zihao Xiao`

.. _Github: http://github.com/unrealcv/unrealcv
.. _issue tracker: https://github.com/unrealcv/unrealcv/issues
Expand Down
15 changes: 11 additions & 4 deletions docs/reference/model_zoo.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
Model Zoo
=========

We provide compiled virtual worlds to play with. All the digital contents belong to the original author. If the program crash for any reason, you can report `an issue <https://github.com/unrealcv/unrealcv/issues>`__.
We provide compiled virtual worlds to play with. All the digital contents belong to the original author.

- **Notice**: Model Zoo is in experiment now. If you are beginners, we highly recommend you to try RealisitcRendering first to avoid some unknown bugs. If any bugs you found, you can report `an issue <https://github.com/unrealcv/unrealcv/issues>`__. We will fix reported bugs as soon as possible.

.. TODO: add more formal license information
The community maintained games will be hosted in the [github wiki page](http://).
.. Make sure links in this page is always accesible. If I need to move files to a new place, link the new place. Do not use version in the filename, use _master.zip as suffix. So that when others share the link, they always share the _master link.
Run the downloaded binary

- In Mac: Run :code:`[ProjectName].app`
Expand All @@ -16,6 +20,9 @@ Run the downloaded binary

Read :doc:`/plugin/package`, if you are interested in sumbitting a binary to the model zoo.




.. _rr:

RealisticRendering
Expand Down Expand Up @@ -49,7 +56,7 @@ ArchinteriorsVol2Scene1

:Description: ArchinteriorsVol2Scene1 is a scene of a 2 floors apartment.

:Download: `Windows <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene1-Windows-0.3.6.zip>`__, `Linux <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene1-Linux-0.3.6.zip>`__
:Download: `Windows <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene1-Windows-0.3.6.zip>`__, `Linux <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene1-Linux-0.3.8.zip>`__


ArchinteriorsVol2Scene2
Expand All @@ -63,7 +70,7 @@ ArchinteriorsVol2Scene2

:Description: ArchinteriorsVol2Scene2 is a scene of a house with 1 bedroom and 1 bathroom.

:Download: `Windows <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene2-Windows-0.3.6.zip>`__, `Linux <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene2-Linux-0.3.6.zip>`__
:Download: `Windows <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene2-Windows-0.3.6.zip>`__, `Linux <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene2-Linux-0.3.8.zip>`__


ArchinteriorsVol2Scene3
Expand All @@ -77,7 +84,7 @@ ArchinteriorsVol2Scene3

:Description: ArchinteriorsVol2Scene3 is a scene of an office.

:Download: `Windows <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene3-Windows-0.3.6.zip>`__, `Linux <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene3-Linux-0.3.6.zip>`__
:Download: `Windows <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene3-Windows-0.3.6.zip>`__, `Linux <http://cs.jhu.edu/~qiuwch/release/unrealcv/ArchinteriorsVol2Scene3-Linux-0.3.8.zip>`__


UrbanCity
Expand Down

0 comments on commit b4ffa48

Please sign in to comment.