I have created this simple pi3d script in the process of trying to learn the framework.
I hit a roadblock where two of the sides are always black when I am rotating the camera. I suspect it is a lighting issue, but I cannot figure out how to fix it.
I have tried switching the shader to 'uv_light' and defining lights on the planes but that did not work.
I have tried rotating the images to see if the two images where not working but the same two sides showed as black with previous images that worked.
import pi3d
# create display
DISPLAY = pi3d.Display.create(background=(0,0,0,0), frames_per_second=30)
# create shader
shader = pi3d.Shader('uv_flat')
# create textures
textures = []
images = ['DSC_7300-Edit.jpg', 'DSC_7329-Edit.jpg', 'DSC_9253.jpg',
'DSC_0688.jpg', 'DSC_0971.jpg', 'DSC_3320.jpg']
for image in images:
textures.append(pi3d.Texture('textures/'+image))
# create camera
CAMERA = pi3d.Camera(eye=(0.0,0.0,-3.0))
# creat keyboard object
mykeys = pi3d.Keyboard()
# create cube
cube = []
cube.append(pi3d.Plane(z=-0.5))
cube.append(pi3d.Plane(y=0.5, rx=90))
cube.append(pi3d.Plane(x=0.5, ry=90))
cube.append(pi3d.Plane(y=-0.5, rx=90))
cube.append(pi3d.Plane(x=-0.5, ry=90))
cube.append(pi3d.Plane(z=0.5))
# create axes for debuging
axes = []
x = pi3d.Lines(vertices=[(0,0,0),(10,0,0)], line_width=10)
x.set_material((1,0,0)) # red
axes.append(x)
y = pi3d.Lines(vertices=[(0,0,0),(0,10,0)], line_width=10)
y.set_material((0,1,0)) # green
axes.append(y)
z = pi3d.Lines(vertices=[(0,0,0),(0,0,10)], line_width=10)
z.set_material((0,0,1)) # blue
axes.append(z)
# display loop
while DISPLAY.loop_running():
#listen for keystrokes
k = mykeys.read()
if k == 27: # if ESC key is pressed
mykeys.close()
DISPLAY.destroy()
break
elif k == 120: # if x is pressed
CAMERA.rotateX(-15)
CAMERA.rotateY(0)
CAMERA.rotateZ(0)
elif k == 121: # if y is pressed
CAMERA.rotateX(0)
CAMERA.rotateY(-15)
CAMERA.rotateZ(0)
elif k == 122: # if z is pressed
CAMERA.rotateX(0)
CAMERA.rotateY(0)
CAMERA.rotateZ(-15)
for axis in axes:
axis.draw()
for side in cube:
side.draw(shader, [textures[cube.index(side)]])
More info on this question where it was discussed on the Rasberry Pi forum here https://www.raspberrypi.org/forums/viewtopic.php?f=41&t=279770