#!/usr/bin/env python
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Filename, Texture
from panda3d.core import AmbientLight, DirectionalLight, PointLight
from panda3d.core import NodePath, TextNode
from direct.task.Task import Task
from direct.actor.Actor import Actor
from direct.gui.OnscreenText import OnscreenText
import sys
import os
import random
import gltf
import simplepbr
random.seed()
class TeapotOnTVDemo(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.disableMouse()
self.setBackgroundColor((0, 0, 0, 1))
# we now get buffer thats going to hold the texture of our new scene
altBuffer = self.win.makeTextureBuffer("hello", 256, 256)
# now we have to setup a new scene graph to make this scene
altRender = NodePath("new render")
# this takes care of setting up ther camera properly
self.altCam = self.makeCamera(altBuffer)
self.altCam.reparentTo(altRender)
self.altCam.setPos(0, -10, 0)
# get the teapot and rotates it for a simple animation
self.teapot = loader.loadModel('teapot')
self.teapot.reparentTo(altRender)
self.teapot.setPos(0, 0, -1)
self.teapot.hprInterval(1.5, (360, 360, 360)).loop()
# put some lighting on the teapot
dlight = DirectionalLight('dlight')
alight = AmbientLight('alight')
dlnp = altRender.attachNewNode(dlight)
alnp = altRender.attachNewNode(alight)
dlight.setColor((0.8, 0.8, 0.5, 1))
alight.setColor((0.2, 0.2, 0.2, 1))
dlnp.setHpr(0, -60, 0)
altRender.setLight(dlnp)
altRender.setLight(alnp)
# Put lighting on the main scene
plight = PointLight('plight')
plnp = render.attachNewNode(plight)
plnp.setPos(0, 0, 10)
render.setLight(plnp)
render.setLight(alnp)
# Panda contains a built-in viewer that lets you view the results of
# your render-to-texture operations. This code configures the viewer.
self.accept("v", self.bufferViewer.toggleEnable)
self.accept("V", self.bufferViewer.toggleEnable)
self.bufferViewer.setPosition("llcorner")
self.bufferViewer.setCardSize(1.0, 0.0)
# Create the tv-men. Each TV-man will display the
# offscreen-texture on his TV screen.
self.tvMen = []
self.makeTvMan(-5, 30, 1, altBuffer.getTexture(), 0.9)
self.MakeTvCube(1, 10, 1, altBuffer.getTexture(), 1.1)
def makeTvMan(self, x, y, z, tex, playrate):
man = Actor()
man.loadModel('models/mechman_idle')
man.setPos(x, y, z)
man.reparentTo(render)
faceplate = man.find("**/faceplate")
faceplate.setTexture(tex, 1)
man.setPlayRate(playrate, "mechman_anim")
man.loop("mechman_anim")
self.tvMen.append(man)
def MakeTvCube(self, x, y, z, tex, playrate):
man = loader.loadModel('models/box.glb')
man.setPos(x, y, z)
man.reparentTo(render)
faceplate = man.find("**/Cube")
faceplate.setTexture(tex, 1)
#man.setPlayRate(playrate, "mechman_anim")
#man.loop("mechman_anim")
self.tvMen.append(man)
demo = TeapotOnTVDemo()
demo.run()
The cube is just a basic cube mesh exported from blender with an image texture material.