Skip to content
Häfner edited this page Apr 13, 2021 · 3 revisions

The TextureRenderer module is a stage, its sub graph is rendered to a texture. One needs to set a camera and the texture dimensions. The texture can be used in any material, for example on a HUD sprite attached to the user camera.

A typical setup looks like this:

import VR

if hasattr(VR, 'scene'): VR.scene.destroy()
VR.scene = VR.Object('scene', 'light')

box = VR.Geometry('box')
box.setPrimitive('Box 1 1 1 1 1 1')
box.setColor('red')
VR.scene.addChild(box)
	
cam = VR.find('Default')

tr = VR.TextureRenderer()
tr.setup(cam, 300, 300, False)
tr.addLink(VR.find('light'))
VR.getRoot().addChild(tr)
tr.setActive(True)
	
sprite = VR.Sprite('hud')
sprite.setFrom([1,0,-2])
cam.addChild(sprite)
sprite.setMaterial(tr.getMaterial())

The texture can only be used on the graphics card. To for example write the image to file it is necessary to enable readback:

tr.setReadback(True)

Another feature is the streaming of the texture image over TCP. When started, it is possible to connect to the stream server to access the image. This can be tried out by opening in a Browser localhost:5678

tr.setReadback(True)
tr.startServer(5678)

This is useful for example when simulating virtual camera systems and using the video stream somewhere else, for example for AR and QR code tracking.

Clone this wiki locally