I'm lost... Attribute error in Shader.py

61 views
Skip to first unread message

Michael Bottin

unread,
Nov 29, 2016, 7:19:32 AM11/29/16
to pi3d

Hello,

 

I'm a french teacher and I'm using The raspberry Pi with my students.

I'm using Python with them but I don't have any knowledges in 3D.

 

I just would like ta make a demo in Python (2.7) which can control a simple

3D model orientation with accelerometer datas.

 

I think that pi3D library is a good choice to do such kind of thing, so I've

installed it.

 

I'm trying to launch some of the demos but each of them terminates with

an error in 'Shader.py' file :

--> AttributeError : 'NoneType' object has no attribute 'encode'.


I've got the same error with Python 3.

 

Could you help me please.

 

Thanks a lot,

 

Michael B

Paddy

unread,
Dec 1, 2016, 5:19:52 PM12/1/16
to pi3d
Thought I'd replied to the group but nothing here. Almost impossible to use this on a phone with dodgy broadband...  The error  could be caused by the shader file not being loaded for some reason, you can probably tell from the full text of the python error message. It's worth posting that in full anyway  as it will give all the info necessary to solve your problem. 

Michael Bottin

unread,
Dec 1, 2016, 6:07:55 PM12/1/16
to pi3d
Thanks a lot for your answers !!

I joined the screenshot with the error in the terminal window.
I extended the GPU memory to 128 without any improvement...

I assume that it is a problem with a library, but I've tried to uninstall
and reinstall all the modules and requires for Pi3D, but I'm not sure...

I used the latest version of Raspbian Jessie with the PIXEL interface.
My Raspberry is a Pi 3.
2016-12-01-115918_1824x984_scrot.png

Paddy

unread,
Dec 2, 2016, 3:49:57 AM12/2/16
to pi3d
hi, that error *is* because the Shader method isn't finding the two components of the shader (vetex fragment)  looking at it (as  much as I can on my phone) it looks to make assumptions about where pi3d has been installed that might not always hold... but I'm not sure why it normally works fine. I'm afraid you will have to wait till the beginning of next week when I get back and have access to RPi

Paddy

unread,
Dec 2, 2016, 2:05:53 PM12/2/16
to pi3d
Michael, thinking about this on the bus from Essaouira it occurs to me that the ways. path is probably being confused by the /... dist... egg stuff in the path to your pi3d installation. How did you install pi3d? Is it running inside virtual environment?

As I said I will have a look at this when I get back but you could probably get it going by git cloning pi3d and changing pi3d_demos/demos py so the path is wherever you cloned pi3d 

Paddy

unread,
Dec 7, 2016, 5:30:20 AM12/7/16
to pi3d
Michael, I've looked into this now and tried changing to pkg_resources.resource_string() (see http://peak.telecommunity.com/DevCenter/PythonEggs#accessing-package-resources). Could you let me know what process you used to set up pi3d so I can test out if this will fix your problem. Thanks, Paddy

Wayne Keenan

unread,
Dec 7, 2016, 5:49:33 AM12/7/16
to pi3d


On Wednesday, 7 December 2016 10:30:20 UTC, Paddy wrote:
Michael, I've looked into this now and tried changing to pkg_resources.resource_string() (see http://peak.telecommunity.com/DevCenter/PythonEggs#accessing-package-resources). Could you let me know what process you used to set up pi3d so I can test out if this will fix your problem. Thanks, Paddy


Coming to this a bit late, but I think that will fix it as I had the same error as the OP.

I've found modules installed when referenced in the 'install_requires' in a setup.py remain in a zipped egg under Python's 'dist' folder.


Usually not a problem, but it broke pi3d when tries to open resources (e.g. shaders) in it's module 'tree', which it expects to be expanded/unzipped fully.


Paddy

unread,
Dec 7, 2016, 3:06:05 PM12/7/16
to pi3d
Hi, I've pushed up a revised version to github master and pypi.python.org It seems to run all the tests OK but I wasn't experiencing this problem before so I don't know if it's fixed it. Could have a look? 

Michael Bottin

unread,
Dec 8, 2016, 2:10:45 AM12/8/16
to pi3d
Wow, that's great !! This works fine. I uninstalled and then reinstalled pi3D and I was able to display my first 3D shapes !! I thank you very much for the attention you have paid to my problem and the time you have devoted to it. I will be able to integrate the use of Pi3D with my students. thanks again

Paddy

unread,
Dec 8, 2016, 5:48:26 AM12/8/16
to pi3d
Michael, glad you sorted out the problem. Getting feedback on specific issues is the main way of patching bugs so I'm pleased you posted the question.

Looking at your screen capture again I notice that you have two different paths to your installed pi3d for py3 and py2

/usr/local/lib/python3.4/dist-packages/pi3d-2.13-py3.4.egg/..
build/bdist.linux-armv7l/egg/..

I would like to know the commands you used to install in this way. You also look to have pi3d-master cloned on your Raspberry Pi; to get your programs to run using that (in preference to the installed version) you would need to edit the /home/pi/Documents/TempRPi/pi3d_demos-master/demo.py file to

import sys
sys
.path.insert(1, '/home/pi/Documents/TempRPi/pi3d-master')

This was what I meant by my earlier suggestion to get things working, but I hadn't noticed that you had already cloned pi3d!

Finally, your original post referred to controlling a 3D model using gyro inputs. When I have done this in the past there where two issues, 1. the orientation values returned by the gyro are not the same as the sequential rotations used by pi3d (google 'euler angles' for why) so you will get better behavior by using an 'empty' see below. 2. there is a tendency for the rotational position about the vertical axis to drift unless you use correction with a magnetometer which requires trigonometry to reverse from the rotated frame of the sensor.
...
model
= pi3d.Model(file_string='models/quadcopter01.obj')
model
.set_shader(shader)
empty
= pi3d.Triangle(corners=((-0.005, -0.003), (0.0, 0.006), (0.005, -0.003)), y=-2.5, z=20.0)
empty
.add_child(model)
...
while DISPLAY.loop_running():
  empty
.draw()
 
while ser.in_waiting > 10: # serial input from arduino with MPU6050
    line
= ser.readline()
   
if b'ypr' in line or b'euler' in line:
      _
, ry, rx, rz, heading = line.split(b'\t')
      rx
, ry, rz, heading = float(rx), float(ry), float(rz), float(heading)
      model
.rotateToX(rx)
      model
.rotateToZ(rz)
      empty
.rotateToY(heading)
...



Reply all
Reply to author
Forward
0 new messages