如果你知道自己在做什么,我认为这并不太难,但是我最后的实施并不完美,如果你在极端情况下做到这一点,那么加权就会破裂,现在我可以&#39理解它。
基本上,一切都有0到1之间的值,我需要将它们分配给着色器。以下是它如何运作的基本概念
numShaders = 20
i = 0
weight = 0.5
shader = 0
i = 0.5
weight = 0.5
shader = 10
i = 1
weight = 0.5
shader = 20
i = 1
weight = 0
shader = 0
i = 0.5
weight = 0.75
shader = around 15
i = 1
weight = 0.75
shader = 20
加权应该是指数级的(或者理想情况下可以选择控制它的推出方式 - 例如推出意味着0.75重量可以产生17而不是15,但仍然不会超过20),并且只会导致一切如果设置为0或1(或足够接近它),则使用相同的着色器。
我一直想弄明白,但目前没有运气,所以提前谢谢。
如果它有帮助,这适用于0.5的重量,但不适用于其他重量,我不太确定你在哪里增加力量 - numShaders*weight*i*2
此外,旧的实现也在这里,我只是无法将原始部分成功转换为现在有效的部分(一旦我掌握了基础知识,我可能会复制剩下的部分) -
#colourValue = 0 to 1
#shaderAmount = number of shaders in total
#colourExponential = pushing values inwards to give solid colours at edges
#colourRatio = weight
#calculate colour to assign
colourValue = py.getAttr( cube+'.colourValue' )
colourNum = colourValue * shaderAmount - ( (colourValue * shaderAmount) - shaderAmount/2.0 ) / colourExponential
if stretchValues == True:
#stretch out the values from 0 to max
if colourNum + 1 == colourNumHalf:
factor = 0
elif colourNum + 1 < colourNumHalf:
factor = ( -colourNumMin / float( colourNum + 1 ) ) * colourNumMin
elif colourNum + 1 > colourNumHalf:
factor = ( colourNumMax / float( shaderAmount - colourNum + 1 ) ) * colourNumMax
else:
factor = 0
colourNum = int(colourNum + factor)
#fix to stop negative numbers
if colourNum < 0:
colourNum = -colourNum
#set ratio of colours
if colourRatio > 0.5:
colourNum = int( colourNum + ( shaderAmount - colourNum ) ** ( colourRatio * 2 - 1 ) )
elif colourRatio < 0.5:
colourNum = int( colourNum - colourNum ** ( 1 - colourRatio * 2 ) )
colourNum = int(round(colourNum,0))
#stop invalid values
if colourNum < 0:
colourNum = 0
elif colourNum >= shaderAmount:
colourNum = shaderAmount - 1
py.select( shaderName + str(colourNum), noExpand = True )
#check previous shader
try:
oldShader.append(shaderSelect.split('n')[-1])
except:
oldShader.append(shaderAmount - 1)
shaderSelect = py.ls( selection = True )[0]
#stop big jumps in colour
if int(shaderSelect.split('n')[-1]) < int(oldShader[-1]) - 1:
py.select( shaderName + str(int(oldShader[-1])-1), noExpand = True )
#overrides initial calculation for extra smoothness
for i in range(smoothOverride):
if len(oldShader) > (i+1):
if int(oldShader[-1]) != int(oldShader[-2-i]):
py.select( shaderName + str(int(oldShader[-1])), noExpand = True )
shaderSelect = py.ls( selection = True )[0]
编辑:正如埃弗特指出的那样,它实际上是正态分布,我将尝试编写类似于此图的代码,但以0.5为中间点,并且0和1为极端。如果我成功,我会再次编辑问题。