I am trying to create a very simple scene with a colored, movable(!) 2d plane that lies in the background and serves as a canvas for a 3d Model that is positioned in front of it. In order to work with exact pixel values I use a 2d-Camera for the background plane.
As the plane is filling the whole screen it also covers the 3d model. This also is discribed in the pi3d FAQ, see "6. How do I display 2D images in front of a 3D scene? (or behind, for that matter)". That couldn't solve my problem, though. I tried to assign a huge z-value to my background plane plus I am using 2 different cameras as described in the FAQ. Still no 3d model.
Any ideas how this could be solved?
Code: Select all
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" Peter Hess' converted shader for pi3d dynamic texturing """
import demo
import pi3d
DISPLAY = pi3d.Display.create(w=1024, h=600, frames_per_second=30)
#map color values from 0 - 255 to 0.0 - 1.0
def map_color((r, g, b), in_min, in_max, out_min, out_max):
rgb = (r, g, b)
r = (r - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
g = (g - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
b = (b - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
return (r, g, b)
#colors
yellow_int = (252, 213, 0)
yellow = map_color(yellow_int, 0, 255, 0.0, 1.0)
white = (1.0, 1.0, 1.0)
bgndSh = pi3d.Shader("mat_flat")
iconSh = pi3d.Shader("2d_flat")
CAMERA = pi3d.Camera()
CAMERA2D = pi3d.Camera(is_3d=False)
#tex = pi3d.Texture("textures/eden_logo.png", blend=True)
#colored background plane
planeBgnd = pi3d.Plane(camera=CAMERA2D, w=1024, h=600, z=100)
planeBgnd.set_material(yellow)
planeBgnd.set_shader(bgndSh)
#LOGO
endlessKnot = pi3d.Model(file_string='models/teapot.obj', camera=CAMERA, name='endless_knot', z=10)
endlessKnot.set_shader(bgndSh)
endlessKnot.set_material(white)
#planeIcon = pi3d.Plane(camera=CAMERA, x=0, y=0, z=200)
mykeys = pi3d.Keyboard()
while DISPLAY.loop_running():
endlessKnot.draw()
planeBgnd.draw()
endlessKnot.rotateIncY( 1 )
if mykeys.read() == 27:
mykeys.close()
DISPLAY.destroy()
break