View Single Post
Old 12-17-2008, 01:03 PM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
Yes, here is an example of how to create a texture on-the-fly and modify the data at runtime.
import viz

WIDTH = 16

#Create blank texture
tex = viz.addBlankTexture([WIDTH,HEIGHT])

#Create quad to display texture
quad = viz.addTexQuad(pos=(0,1.8,2),texture=tex)

def SetTextureColors(begin,end):
	#Get raw image data buffer
	data = tex.getImageData()

	#Modify image data so it blends from begin to end color
	def getColor(c):
		return [ chr(int(v*255)) for v in c ]

	for y in xrange(HEIGHT):
		for x in xrange(WIDTH):
			index = y*WIDTH*3 + x*3
			r,g,b = getColor(vizmat.Interpolate(begin,end,float(x)/WIDTH))
			data[index] = r
			data[index+1] = g
			data[index+2] = b

	#Notify Vizard that texture data has been modified


#Toggle texture color when space key is pressed
vizact.onkeydown(' ',SetTextureColors,viz.WHITE,vizact.choice([viz.GREEN,viz.BLUE,viz.RED]))
From what you described I don't see why you can't use textures instead of nodes.
Reply With Quote