From be516a422a88721d73f8a40383a91e8353afabea Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:02:55 +0200 Subject: [PATCH 01/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- ...lottingGraphsWithMatplotlibAndUnrealEnginePython.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index 320249460..cceac6af9 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -20,6 +20,16 @@ We will use the third person template ## Installing the Python plugin +Ensure your project/editor has been closed. + +Download the most recent embedded binary release from here: https://github.com/20tab/UnrealEnginePython/releases + +You can use a non-embedded version if you already have python in your system and you are confident with it. The only difference in the tutorial is in where the matplotlib will be installed. For embedded version, the installation will happen in the plugin directory itself. For non-embedded it will be in the python system path. Obviously if your system python installation already includes matplotlib, you can simply skip the related paragraph below. + +Create a Plugins/ directory in your project and unzip the plugin archive into it. + +Re-start your project and in the Edit/Plugins menu you will be able to enable the python plugin: + ![Plugin Installation](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/enable_plugin.png) ## pip-installing matplotlib From d128fa5e9b6977573d9d34e5a84068e8ddb64040 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:05:17 +0200 Subject: [PATCH 02/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- .../PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index cceac6af9..f4dbc08f5 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -26,6 +26,8 @@ Download the most recent embedded binary release from here: https://github.com/2 You can use a non-embedded version if you already have python in your system and you are confident with it. The only difference in the tutorial is in where the matplotlib will be installed. For embedded version, the installation will happen in the plugin directory itself. For non-embedded it will be in the python system path. Obviously if your system python installation already includes matplotlib, you can simply skip the related paragraph below. +>Note: on Linux and Mac system, you will use the system installation (no embedded distributions are provided) or directly the source one. The rest of the tutorial will be platform independent. + Create a Plugins/ directory in your project and unzip the plugin archive into it. Re-start your project and in the Edit/Plugins menu you will be able to enable the python plugin: @@ -34,6 +36,8 @@ Re-start your project and in the Edit/Plugins menu you will be able to enable th ## pip-installing matplotlib +If you installed the embedded distribution, just move to he Plugins/UnrealEnginePython/Binaries/Win64 + ![pip install matplotlib](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/pip_install.png) ## Testing matplotlib in Unreal Engine: generating a graph-texture From fea39c60ad539fdebac70cab80852039677fabc5 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:07:09 +0200 Subject: [PATCH 03/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- ...raphsWithMatplotlibAndUnrealEnginePython.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index f4dbc08f5..8680749c4 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -36,10 +36,26 @@ Re-start your project and in the Edit/Plugins menu you will be able to enable th ## pip-installing matplotlib -If you installed the embedded distribution, just move to he Plugins/UnrealEnginePython/Binaries/Win64 +If you installed the embedded distribution, just move to the Plugins/UnrealEnginePython/Binaries/Win64 directory in your terminal, and run: + +```sh +./python.exe -m pip install matplotlib +``` ![pip install matplotlib](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/pip_install.png) +If you are using a system python installation (or you are on Linux/Mac) just run: + +```sh +pip3 install matplotlib +``` + +or (based on your config) + +```sh +pip install matplotlib +``` + ## Testing matplotlib in Unreal Engine: generating a graph-texture ```python From 84d21731091d8b46e3731af994e0b02a8073bfd2 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:09:31 +0200 Subject: [PATCH 04/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- .../PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index 8680749c4..5e6c517ee 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -58,6 +58,12 @@ pip install matplotlib ## Testing matplotlib in Unreal Engine: generating a graph-texture +Time to check if all is working well. + +We will start by generating a texture asset. The content of this texture will be generated by matplotlib. + +The steps are generating a texture in memory, plotting the graph, transferring the graph data into texture memory, save it as an asset and opening the related editor: + ```python import unreal_engine as ue # EPixelFormat defines the various pixel formats for a texture/image, we will use RGBA with 8bit per channel @@ -101,6 +107,9 @@ ue.open_editor_for_asset(texture) ![Texture Created](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/texture_created.png) + +if you end with the texture editor opened on your new graph, you are ready for the next step + ## Our project: Plotting a Pie chart tracking overlap events Our objective is to have a special blueprint in our level exposing 3 cube in 3 different colors. From 4266e76208ebf6294d8b5971c8d6f433ee1b693c Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:09:58 +0200 Subject: [PATCH 05/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index 5e6c517ee..1dd50eb46 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -108,7 +108,7 @@ ue.open_editor_for_asset(texture) ![Texture Created](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/texture_created.png) -if you end with the texture editor opened on your new graph, you are ready for the next step +if you ended up with the texture editor opened on your new graph, you are ready for the next steps ## Our project: Plotting a Pie chart tracking overlap events From 2c22c917474b91088f807a4ec8adfd0b8c46f112 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:13:03 +0200 Subject: [PATCH 06/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index 1dd50eb46..c748c0a6b 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -134,6 +134,9 @@ We need 4 materials and 1 material instance for the project: ### The "pie chart carpet" blueprint +The first blueprint we are about to create, is the 'carpet' (we call it Graph_Blueprint) + +![Graph Blueprint](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/graph_blueprint.png) ```python From c36e53c93ded64357df071bebf41d5c58b817c35 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:20:41 +0200 Subject: [PATCH 07/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- ...tingGraphsWithMatplotlibAndUnrealEnginePython.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index c748c0a6b..971cf129f 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -62,6 +62,8 @@ Time to check if all is working well. We will start by generating a texture asset. The content of this texture will be generated by matplotlib. +You can use the included python editor to edit your scripts (it is under Wndow/Python Editor), or your favourite one SsublimeText, Vim, PyCharm...) just ensure scripts are under the Content/Scripts directory of your project. + The steps are generating a texture in memory, plotting the graph, transferring the graph data into texture memory, save it as an asset and opening the related editor: ```python @@ -138,6 +140,13 @@ The first blueprint we are about to create, is the 'carpet' (we call it Graph_Bl ![Graph Blueprint](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/graph_blueprint.png) +As you can see it is really simple: + +* add a StaticMeshComponent (as root if you want) with a plane as the mesh and the material instance you created before +* add a Python component with the module as 'plotter' and the class as 'PlotComponent' (this is where the matplotlib part will be) +* add an event dispatcher called 'OnGraphDataUpdated' (this will be triggered whenever the character steps over a cube) + +You can now create (again into Content/Scripts) the plotter.py python script ```python import unreal_engine as ue @@ -175,6 +184,10 @@ class PlotComponent: self.texture.texture_set_data(self.fig.canvas.buffer_rgba()) ``` +The only relevant part is the update_graph function that is triggered by the 'OnGraphDataUpdated' event dispatcher. + +This function receives as the 'platform' argument the Actor triggering the event. This Actor (that we will create in the next phase), expose the counters of the overlapping cubes. We use that values to re-generate our pie chart and uploading it into texture memory whenever the event is triggered + ### The "Plotter Platforms" ### Playing it From d2c7be824692819605385b06e9d8e0dabb374189 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:24:09 +0200 Subject: [PATCH 08/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- .../PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index 971cf129f..a1c9587ac 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -190,6 +190,12 @@ This function receives as the 'platform' argument the Actor triggering the event ### The "Plotter Platforms" +The 'PlotterPlatforms' blueprint, implements the actor containing the 3 cubes and manages the overlapping events as well as incrementing the 3 counters. + +Let's start with the viewport, you need to add 3 static meshes, each with a cube and the related solid-color material we created earlier: + +![PlotterPlatforms Blueprint Viewport](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_viewport.png) + ### Playing it ### Writing a simple unit test From 796d54b6c389262fd2ec2e200113cb3a75ae8be5 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:25:42 +0200 Subject: [PATCH 09/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- .../PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index a1c9587ac..35f00f724 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -196,6 +196,10 @@ Let's start with the viewport, you need to add 3 static meshes, each with a cube ![PlotterPlatforms Blueprint Viewport](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_viewport.png) +then we define a blueprint function 'NotifyPlotter', that will trigger the event dispatcher on the Graph_Blueprint (our carpet): + +![PlotterPlatforms Blueprint Viewport](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_notify_plotter.png) + ### Playing it ### Writing a simple unit test From 7d8e62379b709fc248e9bcf19648755cd0807875 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:27:34 +0200 Subject: [PATCH 10/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- .../PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index 35f00f724..bf7f32b10 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -198,7 +198,11 @@ Let's start with the viewport, you need to add 3 static meshes, each with a cube then we define a blueprint function 'NotifyPlotter', that will trigger the event dispatcher on the Graph_Blueprint (our carpet): -![PlotterPlatforms Blueprint Viewport](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_notify_plotter.png) +![PlotterPlatforms Blueprint Notify Plotter](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_notify_plotter.png) + +finally we have the Event Graph, here we simply increment the related counter variables and call the 'NotifyPlotter' function: + +![PlotterPlatforms Blueprint Event Graph](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_event_graph.png) ### Playing it From 9df1993e3205959178d646a0f256a8bc62216292 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 17 Jun 2017 12:28:39 +0200 Subject: [PATCH 11/11] Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md --- tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md index bf7f32b10..f27ba4ca2 100644 --- a/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md +++ b/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md @@ -204,6 +204,8 @@ finally we have the Event Graph, here we simply increment the related counter va ![PlotterPlatforms Blueprint Event Graph](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/platforms_event_graph.png) +Ensure to add the 3 Integer variables (check the lower-left side of the screenshots) for the counters ! + ### Playing it ### Writing a simple unit test