WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-14-2008, 07:39 AM
south_bank south_bank is offline
Member
 
Join Date: May 2008
Location: Wolverhampton
Posts: 11
Blending/Fading 5 Textures with a Slider

Hi,

I'm trying to create an optional extras car showroom simulation which simulates for example, paint colour options. Rather than having lots of car geometry textured in many different colours and showing/hiding them according to which buttons are selected, I would like to use a slider control to fade/blend between the five different colour options of red, black, white, blue and green.

I have searched the example scripts and help files however the blend script seems only to support two textures. I have also experimented with fading between textures but due to relative inexperience, I'm struggling to find a solution with this method.

Is there another way around this issue that would allow me to control the car's paint colour through the five different colours with a slider , preferably of custom appearance? Any help and suggestions will be greatly appreciated.

Thanks.
Reply With Quote
  #2  
Old 05-14-2008, 05:04 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Here is some sample code that should do what you want. It creates a class that allows to blend between an arbitrary number of values. The slider on the left will blend between 5 different colors and the slider on the right will blend between 5 different textures. Let me know if anything is unclear:
Code:
import viz
viz.go()

class MultiBlender(object):
	
	def __init__(self,values):
		"""Initialize blender with list of values"""
		self.values = values[:]
		self.dv = 1.0 / (len(values)-1)
		
	def getBlendValues(self,p):
		"""Returns begin,end, and percent value to blend between them, given total multiblend percent"""
		begin = int(p // self.dv)
		if begin < 0:
			return self.values[0],self.values[1],0.0
		elif begin >= (len(self.values)-1):
			return self.values[-2],self.values[-1],1.0
		return self.values[begin],self.values[begin+1],(p % self.dv) / self.dv
		
	def getInterpolatedValue(self,p):
		"""Return blended value at percent p, 0-1"""
		begin,end,p = self.getBlendValues(p)
		return vizmat.Interpolate(begin,end,p)
		

#Create quad and a blender that blends between 5 colors
colorQuad = viz.addTexQuad(pos=(-1,1.8,4))
colorBlender = MultiBlender([viz.RED,viz.BLACK,viz.WHITE,viz.BLUE,viz.GREEN])

#Add a slider for the blender
colorSlider = viz.addSlider(pos=(0.25,0.1,0))
def blendColor(pos,node,blender):
	node.color(blender.getInterpolatedValue(pos))
vizact.onslider(colorSlider,blendColor,colorQuad,colorBlender)


#Create quad and a blender that blends between 5 textures
textures = [
	'ball.jpg'
	,'brick.jpg'
	,'gb_noise.jpg'
	,'image2.jpg'
	,'lake3.jpg'
]

texQuad = viz.addTexQuad(pos=(1,1.8,4))
texBlender = MultiBlender([viz.addTexture(file) for file in textures])

#Add a slider for the blender
texSlider = viz.addSlider(pos=(0.75,0.1,0))
def blendTexture(pos,node,blender):
	begin,end,p = blender.getBlendValues(pos)
	node.texture(begin,unit=0)
	node.texture(end,unit=1)
	node.texblend(p,unit=1)
vizact.onslider(texSlider,blendTexture,texQuad,texBlender)
Reply With Quote
  #3  
Old 05-15-2008, 07:59 AM
south_bank south_bank is offline
Member
 
Join Date: May 2008
Location: Wolverhampton
Posts: 11
Thanks for the rapid response, it's much appreciated . It all appears pretty clear on first glance and I think I won't have much trouble with it. Thanks again!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
texblend or visible for multiple textures vizmaster Vizard 10 02-14-2007 03:50 PM
Textures not showing drahcir Vizard 1 08-15-2005 10:43 AM
number of textures to load lucalatini Vizard 2 05-12-2005 05:50 PM
Overlaying Textures with Alpha Masks vjosh Vizard 7 04-06-2005 07:46 PM
PROBLEM: Picture-in-Picture breaks textures?!? vcarlson Vizard 4 10-05-2004 04:22 PM


All times are GMT -7. The time now is 03:57 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC