Commit a666b0f7 authored by Jan Kremer's avatar Jan Kremer

Working on 2D plots.

parent fd5eedd7
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
import unreal_engine as ue
# EPixelFormat defines the various pixel formats for a texture/image, we will use RGBA with 8bit per channel
from unreal_engine.enums import EPixelFormat
import matplotlib
# set the Agg renderer as we do not need any toolkit
import matplotlib.pyplot as plt
# set texture/plot dimensions and dpi, ensure dpi is a float !
width = 1024
height = 1024
dpi = 72.0
# create a new figure with the specified sizes
fig = plt.figure(1)
# plot a simple graph with a label on the y axis
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
# draw the graph (in memory)
# create a texture in memory (will be saved later)
texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
# copy pixels from matplotlib canvas to the texture as RGBA
# save the texture
# open its editor
\ No newline at end of file
import unreal_engine as ue import unreal_engine as ue
from unreal_engine.enums import EPixelFormat
import matplotlib
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np
class PlotComponent: class Hero:
def begin_play(self): # this is called on game start
def begin_play(self):
width = 1024 width = 1024
height = 1024 height = 1024
dpi = 72.0 dpi = 72.0
matplotlib.rcParams.update({'font.size': 32})
matplotlib.rcParams.update({'axes.linewidth': 6})
self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8) self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
# self.uobject.get_owner().StaticMeshComponent.getMaterial(0).set_material_texture_parameter('Graph', self.texture) # self.uobject.get_owner().StaticMeshComponent.getMaterial(0).set_material_texture_parameter('Graph', self.texture)
# self.uobject.get_owner().StaticMeshComponent.createDynamicMaterialInstance() # self.uobject.get_owner().StaticMeshComponent.createDynamicMaterialInstance()
self.uobject.get_owner().StaticMeshComponent.OverrideMaterials[0].set_material_texture_parameter('Graph', self.texture)
# matinst = self.uobject.get_owner().StaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0) # matinst = self.uobject.get_owner().StaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0)
# matinst.set_material_texture_parameter('Graph', self.texture) # matinst.set_material_texture_parameter('Graph', self.texture)
...@@ -23,14 +23,27 @@ class PlotComponent: ...@@ -23,14 +23,27 @@ class PlotComponent:
self.fig.set_dpi(dpi) self.fig.set_dpi(dpi)
self.fig.set_figwidth(width/dpi) self.fig.set_figwidth(width/dpi)
self.fig.set_figheight(height/dpi) self.fig.set_figheight(height/dpi)
self.uobject.get_owner().bind_event('OnRedraw', self.redraw)
self.uobject.get_owner().bind_event('OnDrawPoint', self.draw_point)
self.uobject.get_owner().bind_event('OnGraphDataUpdated', self.update_graph) def redraw(self, x, y, c):
# clear the current plot data
plt.scatter(x, y, marker='o', c=c)
def update_graph(self, platform): bbox = plt.gca().get_position()
# clear the current plot data [xmin, xmax] = plt.gca().get_xlim()
plt.clf() [ymin, ymax] = plt.gca().get_ylim()
# draw a pie chart [[x0, y0], [x1, y1]] = bbox.get_points()
plt.pie([5, 7, 12], colors=['r', 'g', 'b'], labels=['RedCube', 'GreenCube', 'BlueCube'], shadow=True) self.uobject.get_owner().call_function('UpdatePlotBounds', x0, y0, x1, y1, xmin, xmax, ymin, ymax)
def draw_point(self, x, y):
ue.log('plotter draw point')
plt.plot(x, y, 'bo')
self.fig.canvas.draw() self.fig.canvas.draw()
self.texture.texture_set_data(self.fig.canvas.buffer_rgba()) self.texture.texture_set_data(self.fig.canvas.buffer_rgba())
\ No newline at end of file
No preview for this file type
This diff is collapsed.
...@@ -19,7 +19,7 @@ public class ImmersiveAnalytics : ModuleRules ...@@ -19,7 +19,7 @@ public class ImmersiveAnalytics : ModuleRules
{ {
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "PointCloudRuntime", "PointCloudEditor" });
// TODO: remove. was used when HDF5 was added via plugin // TODO: remove. was used when HDF5 was added via plugin
//PrivateDependencyModuleNames.AddRange(new string[] { "HDF5" }); //PrivateDependencyModuleNames.AddRange(new string[] { "HDF5" });
// Fill out your copyright notice in the Description page of Project Settings.
#include "Plot3D.h"
// Sets default values
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Called when the game starts or when spawned
void APlot3D::BeginPlay()
void APlot3D::InitPoints()
// Populate the MyPoints array with 1000 randomly positioned, red points
for (int32 i = 0; i < 1000; i++)
// See FPointCloudPoint for more constructor versions
MyPoints.Emplace(FMath::VRand(), FColor::Red, true);
void APlot3D::InitCloud()
// Construct an empty Point Cloud asset
UPointCloud *MyPointCloud = NewObject<UPointCloud>();
// Assign the generated points to the cloud and automatically rebuild the data
// Alternatively, do not auto-build the data by calling
// MyPointCloud->SetPointCloudData(MyPoints, false);
// Get the target Point Cloud Actor
//APointCloudActor *MyPointCloudActor = MyActorGettingFunction();
// Assign the constructed Cloud
// Called every frame
void APlot3D::Tick(float DeltaTime)
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PointCloud.h"
#include "PointCloudActor.h"
#include "Plot3D.generated.h"
class IMMERSIVEANALYTICS_API APlot3D : public AActor
// Sets default values for this actor's properties
// Called when the game starts or when spawned
virtual void BeginPlay() override;
void InitPoints();
void InitCloud();
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(Category = Plot3D, VisibleAnywhere, BlueprintReadOnly)
TArray<FPointCloudPoint> MyPoints;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment