Getting ready

Raspberry Pi must be directly connected to a display, either via the HDMI or an analog video output. The 3D graphics rendered by the GPU will only be displayed on a local display, even if you are connecting to Raspberry Pi remotely over a network. You will also need to use a locally connected mouse for control (however, keyboard control does work via a SSH connection).

The first time we use pi3d, we will need to download and install it via the following steps:

  1. The pi3d library uses Pillow, a version of the Python Imaging Library that is compatible with Python 3, to import graphics used in models (such as textures
    and backgrounds).

The installation of Pillow has been covered in the Getting ready section of Chapter 3, Using Python for Automation and Productivity.

The commands for the installation are shown in the following code (if you've installed them before, it will skip them and continue):

sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install libjpeg-dev
sudo pip-3.2 install pillow  
  1. We can now use pip to install pi3d using the following command:
sudo pip-3.2 install pi3d    
The pi3d team is continuously developing and improving the library; if you are experiencing problems, it may mean that a new release is not compatible with the previous ones.

You can also check in the Appendix, Hardware and Software List, to confirm which version of pi3d you have and, if required, install the same version listed. Alternatively, contact the pi3d team via the Google group; they will be happy to help!

Obtain pi3d demos from the GitHub site, as shown in the following command lines. You will need around 90 MB of free space to download and extract the files:

  cd ~

  wget 
  https://github.com/pi3d/pi3d_demos/archive/master.zip


  unzip master.zip

  rm master.zip

You will find that the demos have been unpacked to pi3d_demos-master.

By default, the demos are expected to be located at home/pi/pi3d; therefore, we will rename this directory pi3d, as shown in the following command:

mv pi3d_demos-master pi3d  
  1. Finally, check the Raspberry Pi memory split. Run raspi-config (sudo raspi-config) and ensure that your memory split is set to 128. (You should only need to do this if you have changed it in the past, as 128 MB is the default.) This ensures that you have plenty of RAM allocated for the GPU, so it will be able to handle lots of 3D objects if required.
  2. Test if everything is working properly. You should now be able to run any of the scripts in the pi3d_demos-master directory. See the pi3d Wiki pages for details on how they function (http://pi3d.github.io/html/ReadMe.html). To get the best performance, it is recommended that the scripts are run from the command prompt (without loading the desktop):
cd pi3d
python3 Raspberry_Rain.py     
The pi3d.Keyboard object also supports keyboard control via SSH (see the Connecting remotely to Raspberry Pi over the network using SSH (and X11 forwarding) section of Chapter 1, Getting Started with a Raspberry Pi 3 Computer).

Configure the setup for your own scripts. Since we will use some of the textures and models from the demos, it is recommended that you create your scripts within the pi3d directory. If you have a username that's different from the default Pi account, you will need to adjust /pi3d/demo.py. Replace the USERNAME part with your own username by editing the file:

  nano ~/pi3d/demo.py

  import sys

  sys.path.insert(1, '/home/USERNAME/pi3d')

If you want to relocate your files somewhere else, ensure that you add a copy of demo.py in the folder with the correct path to any resource files you require.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.117.214