#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
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) |
#3
|
|||
|
|||
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!
|
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
texblend or visible for multiple textures | vizmaster | Vizard | 10 | 02-14-2007 04:50 PM |
Textures not showing | drahcir | Vizard | 1 | 08-15-2005 11:43 AM |
number of textures to load | lucalatini | Vizard | 2 | 05-12-2005 06:50 PM |
Overlaying Textures with Alpha Masks | vjosh | Vizard | 7 | 04-06-2005 08:46 PM |
PROBLEM: Picture-in-Picture breaks textures?!? | vcarlson | Vizard | 4 | 10-05-2004 05:22 PM |