nurik
Posts: 2
Joined: Tue Aug 29, 2017 3:08 pm

Pi3D - 2D "Dashboard"

Tue Aug 29, 2017 3:37 pm

Hi,

I am creating this live 3D model of the kinematics of a humanoid 'robot' I am working on.

I am trying to create some sort of 2D 'dashboard/HUD' type of thing on my screen, which would display some live data in text format (e.g. the value of the angles of joints) and also visual information. I have figured out how to display 2D text using 2 camera objects, 1 for the 3D models (CAMERA=pi3d.Camera(eye=(xcam,ycam,zcam), at = (0,0.5,0) )) and another one for displaying for text (CAMERA2D = pi3d.Camera(is_3d=False)).

I am now trying to complete the second task of creating the visual 2D objects. I have attached a drawing of roughly what I want to create as part of the 'HUD/dashboard'. Whole idea is to visualise the centre of mass of my robot, and how close it is to regions of toppling (green = no toppling, red = high risk of toppling), the blue circle being the centre of mass. In simple terms - I basically need to create, some rectangular boxes (or doesn't even have to be boxes, can be fully painted rectangles), with a DOT/POINT within the box/rectangle. I, initially, thought that I could use the 'Shape' module and spawn cuboids and spheres and by specifying camera = CAMERA2D, would convert them into 2D objects but this turned out to be unsuccessful.

I found something similar to what I want, which is from pi3d demo called 'TigerTank.py', they create a HUD for minimap at bottom right of the screen by spawning 'Sprite' objects and applying textures to it. Is this the only way to create 2D shapes that are projected onto your screen? Or is there any other possible way to achieve this? Maybe, it is possible to do it the way I attempted to initially (by spawning Shapes and specifying the camera = CAMERA2D)? Maybe, I just need extra settings?
Attachments
idea.png
idea.png (2.43 KiB) Viewed 1068 times

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Pi3D - 2D "Dashboard"

Tue Aug 29, 2017 8:46 pm

There is a SciPy library for all sorts of science maths see https://www.scipy.org/

1 of the libraries is the Matplotlib witch is exactly for what you want to do see http://matplotlib.org/

nurik
Posts: 2
Joined: Tue Aug 29, 2017 3:08 pm

Re: Pi3D - 2D "Dashboard"

Wed Aug 30, 2017 9:47 am

OutoftheBOTS wrote:
Tue Aug 29, 2017 8:46 pm
There is a SciPy library for all sorts of science maths see https://www.scipy.org/

1 of the libraries is the Matplotlib witch is exactly for what you want to do see http://matplotlib.org/
You didn't understand my problem, I am already using Pi3d library to visualise the thing. I just need to project a dashboard onto the screen. To better explain this, I included a screenshot of what I currently have made. The bottom left 2 corners have placeholder text. In the top right (red box) is the location where I want to visualise what I said in my earlier post (about the box with a dot). How would I create a box shape in Pi3D to be projected in 2D on to the screen (the same way the texts in bottom corners are) ? One way , I have found so far, was to use Sprites module from Pi3D and apply textures, the same way they done the minimap in TigerTank.py demo but I just want simple rectangular shapes and dots, is there another way of doing this?
Attachments
EXAMPLE.png
EXAMPLE.png (72.71 KiB) Viewed 1022 times

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Pi3D - 2D "Dashboard"

Wed Aug 30, 2017 10:21 am

Ok I am not sure how to display the data you want with in the Pi3d window but the Matplotlib is designed to display the data you want in the way you want it but it would get displayed in another window. You should be able to place that window in the foreground about your Pi3d window. If that helps

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D - 2D "Dashboard"

Thu Aug 31, 2017 11:41 am

@nurik,

It's not too hard to add 2D stuff in front of 3D in pi3d - I think the TigerTank demo code needs revising as it's rather old now. If you start from a normal 3D app the simplest way is to create: a 2D Camera instance, a 'flat' shader, some flat shapes to draw (Sprite, Plane, Disk, Triangle etc)
You need to set the z values to layer them but most z values after 2D projection are well in front of any 3D vertices (see FAQ). So I added the following lines to the Orbit demo:

Code: Select all

...
CAM2D = pi3d.Camera(is_3d=False)
...
matsh = pi3d.Shader("mat_flat")
W, H = 400, 200
# remember 0,0 is in the centre of Shapes and the Display, x L to R, y D to Up
rect = pi3d.Sprite(w=W, h=H, x=(DISPLAY.width - W) / 2, 
                   y=(DISPLAY.height - H) / 2, z=2, camera=CAM2D)
rect.set_shader(matsh)
rect.set_material((0.0, 1.0, 0.5))
ball = pi3d.Disk(radius=25, sides=36, z=1, rx=90, camera=CAM2D) # default orientated in x,z plane so rotate
ball.set_shader(matsh)
ball.set_material((1.0, 0.5, 0.0))
...
  ball.positionX(DISPLAY.width / 2 - (fr % 100)) # obviously you would set this to something meaningful
  ball.positionY(DISPLAY.height / 2 - (fr % 205))
  ball.draw()
  rect.draw()
  ...
It might be nicer to use images rather than material colours in which case you would need to use "uv_flat" shader and rect.set_draw_details()

PS looking again at your attached image you already probably have a 2D camera and flat shader to draw your text so you "just" need your flat shapes.
PPS. Revised TigerTank.py and TigerShadow.py on develop branch https://github.com/pi3d/pi3d_demos/blob ... gerTank.py
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”