pi3d 点亮立方体的所有面
pi3d light all sides of cube
我在尝试学习框架的过程中创建了这个简单的 pi3d 脚本。
我遇到了一个障碍,当我旋转相机时,有两个边总是黑色的。我怀疑这是一个照明问题,但我不知道如何解决它。
我试过将着色器切换到 'uv_light' 并在平面上定义灯光,但这没有用。
我已经尝试旋转图像以查看两个图像是否不起作用但相同的两侧显示为黑色而之前的图像有效。
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)]])
关于此问题的更多信息,在此处的 Rasberry Pi 论坛上进行了讨论 https://www.raspberrypi.org/forums/viewtopic.php?f=41&t=279770
我在尝试学习框架的过程中创建了这个简单的 pi3d 脚本。
我遇到了一个障碍,当我旋转相机时,有两个边总是黑色的。我怀疑这是一个照明问题,但我不知道如何解决它。
我试过将着色器切换到 'uv_light' 并在平面上定义灯光,但这没有用。
我已经尝试旋转图像以查看两个图像是否不起作用但相同的两侧显示为黑色而之前的图像有效。
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)]])
关于此问题的更多信息,在此处的 Rasberry Pi 论坛上进行了讨论 https://www.raspberrypi.org/forums/viewtopic.php?f=41&t=279770