背景用の頂点カラーツールです
開発途中で、SI終了の報がきたので、
投げちゃったのですが、
要望があったのでさらしてみます
グラデーションの塗りを緩和します
どうやら、複数のオブジェクトにはまだバギーな動きをしてますが、
リペイントで対応してください :p
自分が必要であれば対応しますw
使用の想定
・ハイトマップ、多メッシュでの一様なグラデーション
・手作業での頂点へのライティング
・選択したオブジェクトの明るさなどの調整(未完
つかいかたっぽいもの
選択した、オブジェクト、エッジ、頂点に対し
頂点カラーを設定、調整します
※頂点カラーはあらかじめ設定してやってください
コード
ScriptEditorにコピペして、
実行してください
・・・すごい適当ですみません
from win32com.client import constants as c
app = Application; log = app.LogMessage
BUTTONSIZE_LW = 50
BUTTONSIZE_LH = 48
def createLayout(cp,ColorList,FCurveColorList):
log(cp)
oly = cp.PPGLayout
oly.AddTab( "Main" )
oly.AddItem("ToPntSamples")
oly.AddGroup("PerCent",False,10)
oItem = oly.AddItem("Percent")
#oItem.SetAttribute("cx",30)
#oItem.SetAttribute("cy",30)
oItem = oItem.SetAttribute("NoLabel",True)
oly.EndGroup()
#SetColor
#--------------------------------------------
oly.AddGroup("SetColor")
oly.AddRow()
oItem = oly.AddButton("Pick_SetColor","Pick")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("cy",BUTTONSIZE_LH)
oItem = oly.AddColor( ColorList[0] + "_red", ColorList[0],True)
oItem.SetAttribute("NoLabel",True)
oItem = oly.AddButton("SetColor","Set")
oItem.SetAttribute("cx",50)
oItem.SetAttribute("cy",48)
oly.EndRow()
oly.AddRow()
oly.EndRow()
oly.EndGroup()
#
# #UpperLayer
# #--------------------------------------------
# oly.AddGroup("UpperLayer")
# oly.AddRow()
# oItem = oly.AddButton("Pick_UpperLayer","Pick")
# oItem.SetAttribute("cx",BUTTONSIZE_LW)
# oItem.SetAttribute("cy",BUTTONSIZE_LH)
# oItem = oly.AddColor( ColorList[1] + "_red", ColorList[1],False)
# oItem.SetAttribute("NoLabel",True)
# oly.EndRow()
#
# oly.AddGroup("Darken")
# oly.AddRow()
# oly.AddButton("Multiple")
# oly.AddButton("HardLight")
# oly.AddButton("Burn")
# oly.EndRow()
# oly.EndGroup()
#
# oly.AddGroup("Lightn")
# oly.AddRow()
# oly.AddButton("Screen")
# oly.AddButton("ColorDodge")
# oly.AddButton("LinerDodge")
# oly.EndRow()
# oly.EndGroup()
#
# oly.AddGroup("Contrast")
# oly.AddRow()
# oly.AddButton("OverLay")
# oly.AddButton("SoftLight")
# oly.EndRow()
# oly.EndGroup()
#
# oly.EndGroup()
#ColorMath
#--------------------------------------------
oly.AddGroup("ColorMath")
oly.AddRow()
oItem = oly.AddButton("Pick_ColorMath","Pick")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("cy",BUTTONSIZE_LH)
oItem = oly.AddColor( ColorList[2] + "_red", ColorList[2],False)
oItem.SetAttribute("NoLabel",True)
oItem = oly.AddButton("ColorMath_Sub","Sub")
oItem.SetAttribute("cx",30)
oItem.SetAttribute("cy",48)
oItem = oly.AddButton("ColorMath_Add","Add")
oItem.SetAttribute("cx",30)
oItem.SetAttribute("cy",48)
oly.EndRow()
oly.AddRow()
oly.AddGroup("SetColor")
oly.AddRow()
oly.AddButton("ColorMath_00","|0|")
oly.AddButton("ColorMath_x05","x0.5")
oly.AddButton("ColorMath_x08","x0.8")
oly.AddButton("ColorMath_05","|0.5|")
oly.AddButton("ColorMath_x12","x1.2")
oly.AddButton("ColorMath_x20","x2")
oly.AddButton("ColorMath_10","|1.0|")
oly.EndRow()
oly.EndGroup()
oly.EndRow()
oly.EndGroup()
#+ Gra ++++++++++++++++++++++++++++++++++++++++++
oly.AddTab( "Grad" )
oly.AddItem("ToPntSamples")
#-Percent-------------------
oly.AddGroup("PerCent",False,10)
oItem = oly.AddItem("Percent")
oItem = oItem.SetAttribute("NoLabel",True)
oly.EndGroup()
oly.AddGroup("Gradation")
#oly.AddButton("test")
oly.AddRow()
oItem = oly.AddButton("Gradation_Exe","Paint")
oItem.SetAttribute("cx",100)
oItem.SetAttribute("cy",48)
oItem = oly.AddButton("RePaint","Re Paint")
oItem.SetAttribute("cx",100)
oItem.SetAttribute("cy",48)
oly.EndRow()
#-Type
oly.AddGroup("Composit")
Array = ["Normal",0,"Multiple",1]
oItem = oly.AddEnumControl("GraComposition",Array,"Comp",c.siControlCombo)
oItem.SetAttribute("NoLabel", True)
oly.EndGroup()
oly.AddRow()
oly.AddGroup("Color")
Array = ["Color1 > Bace",0,"Color1 > Color2",1]
oItem = oly.AddEnumControl("GraColorPattern",Array,"ColorPattern",c.siControlCombo)
oItem.SetAttribute("NoLabel", True)
oly.EndGroup()
oly.AddGroup("Form")
oItem = oly.AddEnumControl("GraForm",["Linear",0,"Radial",1],"Comp",c.siControlCombo)
oItem.SetAttribute("NoLabel", True)
oly.EndGroup()
oly.EndRow()
#- FCurve Color -------------------
oly.AddGroup("Color1")
oly.AddRow()
oItem = oly.AddButton("Pick_FCurveColor1","Pick")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("cy",BUTTONSIZE_LH)
oItem = oly.AddColor( FCurveColorList[0] + "_red", FCurveColorList[0],True)
oItem.SetAttribute("NoLabel",True)
oly.EndRow()
oly.AddRow()
oly.EndRow()
oly.EndGroup()
oly.AddGroup("Color2")
oly.AddRow()
oItem = oly.AddButton("Pick_FCurveColor2","Pick")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("cy",BUTTONSIZE_LH)
oItem = oly.AddColor( FCurveColorList[1] + "_red", FCurveColorList[1],True)
oItem.SetAttribute("NoLabel",True)
oly.EndRow()
oly.AddRow()
oly.EndRow()
oly.EndGroup()
#-Position-------------------
oly.AddGroup("Start_Position")
oly.AddRow()
oItem = oly.AddButton("pick_aPosButton","Pick")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem = oly.AddItem("aPosX","x")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("noslider",True)
oItem.SetAttribute("NoLabel",True)
oItem = oly.AddItem("aPosY","y")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("noslider",True)
oItem.SetAttribute("NoLabel",True)
oItem = oly.AddItem("aPosZ","z")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("noslider",True)
oItem.SetAttribute("NoLabel",True)
oly.EndRow()
oly.EndGroup()
oly.AddGroup("End_Position")
oly.AddRow()
oItem = oly.AddButton("pick_bPosButton","Pick")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem = oly.AddItem("bPosX","x")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("noslider",True)
oItem.SetAttribute("NoLabel",True)
oItem = oly.AddItem("bPosY","y")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("noslider",True)
oItem.SetAttribute("NoLabel",True)
oItem = oly.AddItem("bPosZ","z")
oItem.SetAttribute("cx",BUTTONSIZE_LW)
oItem.SetAttribute("noslider",True)
oItem.SetAttribute("NoLabel",True)
oly.EndRow()
oly.EndGroup()
#-FCurve-------------------
oly.AddGroup("PaintGradation")
oly.AddFCurve("FCurve",150)
oly.EndGroup()
oly.EndGroup()
return oly
#---------------------------------------------------
# addColorParam3
#---------------------------------------------------
def addColorParam3(cp,inName):
colorList = ["red","green","bule","alpha"]
colorList = [inName + "_" + i for i in colorList]
for i in colorList:
cp.AddParameter3( i, c.siDouble,1,0,1 ,False)
#---------------------------------------------------
# addColorParam
#---------------------------------------------------
def addColorParam(cp,colorList):
#SetColor
for i in colorList:
addColorParam3(cp,i)
#---------------------------------------------------
# addOtherParam
#---------------------------------------------------
def addOtherParam(cp):
cp.AddParameter3("Percent",c.siDouble,100,0.01,100,False)
cp.AddParameter3("ToPntSamples",c.siBool,False,"","",False)
oFCParam = cp.AddFCurveParameter("FCurve")
oFCurve = oFCParam.Value
oFCurve.BeginEdit()
oFCurve.RemoveKeys()
oFCurve.AddKey( 100, 0)
oFCurve.AddKey( 0, 1)
oFCurve.Interpolation = 2
oFCurve.EndEdit();
#Gradation
cp.AddParameter3("GraComposition", c.siInt4, 0,0,1,False)
cp.AddParameter3("GraColorPattern", c.siInt4,0,0,1,False)
cp.AddParameter3("GraForm", c.siInt4, 0,0,1,False)
cp.AddParameter3("GraPercentage", c.siDouble,100,0.01,100,False)
cp.AddParameter3("aPosX",c.siDouble,0,-10000,10000,False)
cp.AddParameter3("aPosY",c.siDouble,0,-10000,10000,False)
cp.AddParameter3("aPosZ",c.siDouble,0,-10000,10000,False)
cp.AddParameter3("bPosX",c.siDouble,0,-10000,10000,False)
cp.AddParameter3("bPosY",c.siDouble,10,-10000,10000,False)
cp.AddParameter3("bPosZ",c.siDouble,0,-10000,10000,False)
oFCurve.EndEdit()
def lyLogic(ly):
ly.Language = "Python"
ly.Logic = """
app = Application; log = app.LogMessage
def test_OnClicked():
fc = PPG.FCurve.Value
log("Test")
log(fc.Eval(20))
def getMixPercentage(inA,inB,inPercentage):
aValue = inA * inPercentage / 100
bValue = inB * ( 100 - inPercentage) / 100
return aValue + bValue
# pickVertexRGBA
#---------------------------------
def pickVertexRGBA():
oSel = app.Selection
currentFilter = oSel.Filter
app.SetSelFilter("SampledPoint")
oPick = app.PickElement()
#log(oPick(2))
if oPick(0) != 0:
pickSample = oPick(2).SubComponent.ComponentCollection(0).Index
else :
log(Cancel)
app.SetSelFilter(currentFilter)
pickSample = -1
return False
app.SetSelFilter(currentFilter)
getVArray = oPick(2).SubComponent.Parent3DObject.ActivePrimitive.Geometry.CurrentVertexColor
if getVArray == None:
return False
aRGBAs = getVArray.Elements.Array
return [ aRGBAs[0][pickSample], aRGBAs[1][pickSample], aRGBAs[2][pickSample], aRGBAs[3][pickSample] ]
def Up_OnClicked():
Inspects = PPG.Inspected
for Inspected in Inspects:
log(Inspected.Parameters("base_red") )
Inspected.Parameters("base_red").Value = .1
for oPrames in Inspected.Parameters:
log(oPrames)
#oParams("base_red").Value = .1
return
def SetColorMathParam(in_Vale):
PPG.Math_red.Value = in_Vale
PPG.Math_green.Value = in_Vale
PPG.Math_bule.Value = in_Vale
#PPG.Math_alpha.Value = in_Vale
return
#------------------------------------------------------
def minmax(inValue):
if inValue < 0:
return 0.0
elif inValue > 1:
#log("a")
return 1.0
else :
return inValue
def SetColorMulMathParam(in_Vale):
PPG.Math_red.Value = minmax( PPG.Math_red.Value * in_Vale )
PPG.Math_green.Value = minmax( PPG.Math_green.Value * in_Vale )
PPG.Math_bule.Value = minmax( PPG.Math_bule.Value * in_Vale )
#PPG.Math_alpha.Value = minmax( PPG.Math_alpha.Value * in_Vale )
return
#------------ScalerAlglithm--------------------------
def ScalerSub(inA,inB):
return inA - inB
def ScalerAdd(inA,inB):
return inA + inB
#
def scalerMultiple(bg,fg):
return fg * bg
#スクリーン
def scalerScreen(bg,fg):
return 1 - ( ( 1 - bg ) * ( 1 - fg ) )
#オーバーレイ
def scalerOverLay(bg,fg):
if bg < 0.5:
return 2.0 * bg * fg
if bg >= 0.5:
return 1 - 2 * ( ( 1- bg ) * ( 1- fg ) )
#ソフトライト
def scalerSoftLight(bg,fg):
if fg < 0.5:
return bg ** ( 2 * ( 1 - fg ) )
if fg >= 0.5:
return bg ** ( 1 / ( 2 * fg ) )
#ハードライト
def scalerHardLight( bg, fg ):
if fg < 0.5:
return bg * fg * 2
if fg >= 0.5:
return 1 - 2 * ( 1 - bg) * ( 1 - fg )
#焼き込み
def scalerBurn(bg,fg):
if fg == 0:
return 1
return 1.0 - ( 1.0 + bg ) / fg
#覆いカラー
def scalerDodge(bg,fg):
if bg + fg > 1.0:
return 1.0
elif bg > 0:
return bg /(1.0 - fg )
else :
return 0.0
#覆い焼きリニア
def scalerLinearDodge(bg,fg):
if bg + fg > 1.0:
return 1
else :
return bg + fg
#------------------------------------------
def setRGB(aVC,sID,inPercent):
#R
aVC[0][sID] = getMixPercentage( PPG.Set_red.Value , aVC[0][sID],inPercent)
#G
aVC[1][sID] = getMixPercentage( PPG.Set_green.Value , aVC[1][sID],inPercent)
#B
aVC[2][sID] = getMixPercentage( PPG.Set_bule.Value , aVC[2][sID],inPercent)
#A
aVC[3][sID] = getMixPercentage( PPG.Set_alpha.Value , aVC[3][sID],inPercent)
def Set_ColorMath_Sub_RGB(aVC,sID,inPercent):
#R
aVC[0][sID] = minmax ( getMixPercentage( ScalerSub(aVC[0][sID],PPG.Math_red.Value) , aVC[0][sID],inPercent) )
#G
aVC[1][sID] = minmax ( getMixPercentage( ScalerSub(aVC[1][sID],PPG.Math_green.Value) , aVC[1][sID],inPercent) )
#B
aVC[2][sID] = minmax ( getMixPercentage( ScalerSub(aVC[2][sID],PPG.Math_bule.Value) , aVC[2][sID],inPercent) )
#A
#aVC[3][sID] = minmax ( getMixPercentage( ScalerSub(aVC[3][sID],PPG.Math_alpha.Value) , aVC[3][sID],inPercent) )
def Set_ColorMath_Add_RGB(aVC,sID,inPercent):
#R
aVC[0][sID] = minmax ( getMixPercentage( ScalerAdd(aVC[0][sID],PPG.Math_red.Value) , aVC[0][sID],inPercent) )
#G
aVC[1][sID] = minmax ( getMixPercentage( ScalerAdd(aVC[1][sID],PPG.Math_green.Value) , aVC[1][sID],inPercent) )
#B
aVC[2][sID] = minmax ( getMixPercentage( ScalerAdd(aVC[2][sID],PPG.Math_bule.Value) , aVC[2][sID],inPercent) )
#A
#aVC[3][sID] = minmax ( getMixPercentage( ScalerAdd(aVC[3][sID],PPG.Math_alpha.Value) , aVC[3][sID],inPercent) )
#Set
#----------------------------------------
#----------------------------------
# getSelectSampleIDs
#----------------------------------
def getSelectSampleIDs(oSel,gToPntSmps):
#oGeo = oSel.ActivePrimitive.Geometry
#VC = oGeo.CurrentVertexColor
log(oSel.Type)
oSmpIDs = []
#Obj
if oSel.Type == "polymsh":
oGeo = oSel.ActivePrimitive.Geometry
VC = oGeo.CurrentVertexColor
if VC == None:
return -1
oSmpIDs = range(oGeo.Samples.Count)
#poly
elif oSel.Type == "polySubComponent":
oSub = oSel.SubComponent
oColl = oSel.SubComponent.ComponentCollection
#PolygonPnt Poly > pnt > sample
if gToPntSmps:
for oPoly in oColl:
oPnts = oPoly.Points
for oPnt in oPnts:
oSamples = oPnt.Samples
for oSmp in oSamples:
oSmpIDs.append(oSmp.Index)
#Poly > Sampe
else :
for oPoly in oColl:
oSamples = oPoly.Samples
for oSmp in oSamples:
oSmpIDs.append(oSmp.Index)
#Edge
elif oSel.Type == "edgeSubComponent":
oSub = oSel.SubComponent
oColl = oSel.SubComponent.ComponentCollection
#PolygonPnt Edge > pnt > sample
if gToPntSmps:
for oEdge in oColl:
oPnts = oEdge.Points
for oPnt in oPnts:
oSamples = oPnt.Samples
for oSmp in oSamples:
oSmpIDs.append(oSmp.Index)
#Poly > Sampe
else :
for oEdge in oColl:
oSamples = oEdge.Samples
for oSmp in oSamples:
oSmpIDs.append(oSmp.Index)
#Point
elif oSel.Type == "sampleSubComponent":
oColl = oSel.SubComponent.ComponentCollection
for oSmp in oColl:
oSmpIDs.append(oSmp.Index)
#Sample
elif oSel.Type == "pntSubComponent":
oColl = oSel.SubComponent.ComponentCollection
for oPnt in oColl:
oSamples = oPnt.Samples
for oSmp in oSamples:
oSmpIDs.append(oSmp.Index)
else :
log("Pls Select Poly or Pnt")
return -1
return oSmpIDs
# SetColor
#-------------------------------
def SetColor(DrawingMode):
gToPntSmps = PPG.ToPntSamples.Value
gPacentege = PPG.Percent.Value
oSels = app.Selection
for oSel in oSels:
oSmpIDs = getSelectSampleIDs(oSel,gToPntSmps)
if oSmpIDs == -1:
continue
if oSel.Type != "polymsh":
oSub = oSel.SubComponent
oObj = oSub.Parent3DObject
else:
oObj = oSel
oGeo = oObj.ActivePrimitive.Geometry
Clusters = oGeo.Clusters.Filter("sample")
for Cls in Clusters:
for oProp in Cls.Properties:
if(oProp.Name == "Vertex_Color"):
aVC = oProp.Elements.Array
aVC = [list(aVC[0]),list(aVC[1]),list(aVC[2]),list(aVC[3])]
#SetColor
if DrawingMode == "Set":
for i in oSmpIDs:
setRGB(aVC,i,gPacentege)
#ColorMath_Sub
if DrawingMode == "ColorMath_Sub":
for i in oSmpIDs:
Set_ColorMath_Sub_RGB(aVC,i,gPacentege)
#ColorMath_Add
if DrawingMode == "ColorMath_Add":
for i in oSmpIDs:
Set_ColorMath_Add_RGB(aVC,i,gPacentege)
#Burn
if DrawingMode == "Burn":
for i in oSmpIDs:
rgbBurn(aVC,i)
#Dodge
if DrawingMode == "Dodge":
for i in oSmpIDs:
rgbDodge(aVC,i)
#Multiple
if DrawingMode == "Multiple":
for i in oSmpIDs:
rgbMultiple(aVC,i)
oProp.Elements.Array = aVC
def SetColor_OnClicked():
SetColor("Set")
return
def ColorMath_Sub_OnClicked():
log("Sub")
SetColor("ColorMath_Sub")
return
def ColorMath_Add_OnClicked():
log("Add")
SetColor("ColorMath_Add")
return
def ColorMath_00_OnClicked():
SetColorMathParam(0.0)
return
def ColorMath_x05_OnClicked():
SetColorMulMathParam(0.5)
return
def ColorMath_x08_OnClicked():
SetColorMulMathParam(0.8)
return
def ColorMath_05_OnClicked():
SetColorMathParam(0.5)
return
def ColorMath_x12_OnClicked():
SetColorMulMathParam(1.2)
return
def ColorMath_x20_OnClicked():
SetColorMulMathParam(2.0)
return
def ColorMath_10_OnClicked():
SetColorMathParam(1.0)
return
#----------------------------------------
#Pick VertexColor
#----------------------------------------
def Pick_FCurveColor1_OnClicked():
rgba = pickVertexRGBA()
if rgba == False:
return
PPG.FCurve1_red.Value = rgba[0]
PPG.FCurve1_green.Value = rgba[1]
PPG.FCurve1_bule.Value = rgba[2]
PPG.FCurve1_alpha.Value = rgba[3]
return
def Pick_FCurveColor2_OnClicked():
rgba = pickVertexRGBA()
if rgba == False:
return
PPG.FCurve2_red.Value = rgba[0]
PPG.FCurve2_green.Value = rgba[1]
PPG.FCurve2_bule.Value = rgba[2]
PPG.FCurve2_alpha.Value = rgba[3]
return
def Pick_SetColor_OnClicked():
rgba = pickVertexRGBA()
if rgba == False:
return
PPG.Set_red.Value = rgba[0]
PPG.Set_green.Value = rgba[1]
PPG.Set_bule.Value = rgba[2]
PPG.Set_alpha.Value = rgba[3]
return
def Pick_UpperLayer_OnClicked():
rgba = pickVertexRGBA()
if rgba == False:
return
PPG.UpperLayer_red.Value = rgba[0]
PPG.UpperLayer_green.Value = rgba[1]
PPG.UpperLayer_bule.Value = rgba[2]
PPG.UpperLayer_alpha.Value = rgba[3]
return
def Pick_ColorMath_OnClicked():
rgba = pickVertexRGBA()
if rgba == False:
return
PPG.Math_red.Value = rgba[0]
PPG.Math_green.Value = rgba[1]
PPG.Math_bule.Value = rgba[2]
PPG.Math_alpha.Value = rgba[3]
return
#-Gra--------------------------------------
def pickPosition():
oPos = XSIMath.CreateVector3()
oPick = app.PickPosition()
if oPick(0) == 0:
log("Pick Cancel")
return -1
oPos.X = oPick(1)
oPos.Y = oPick(2)
oPos.Z = oPick(3)
return oPos
def setAPosition():
oPos = pickPosition()
if oPos == -1:
return
PPG.aPosX.Value = oPos.X
PPG.aPosY.Value = oPos.Y
PPG.aPosZ.Value = oPos.Z
return
def setBPosition():
oPos = pickPosition()
if oPos == -1:
return
PPG.bPosX.Value = oPos.X
PPG.bPosY.Value = oPos.Y
PPG.bPosZ.Value = oPos.Z
return
def pick_aPosButton_OnClicked():
log("pick_aPos")
setAPosition()
return
def pick_bPosButton_OnClicked():
log("pick_bPos")
setBPosition()
return
#----------------------------------
# pickPosition
#----------------------------------
def pickPosition():
oPos = XSIMath.CreateVector3()
oPick = app.PickPosition()
if oPick(0) == 0:
log("Pick Cancel")
return -1
oPos.X = oPick(1)
oPos.Y = oPick(2)
oPos.Z = oPick(3)
return oPos
#------------------------------
# getGlobalPntsPositions
#------------------------------
def getGlobalPntsPositions(oObj,activePoints):
oGeo = oObj.ActivePrimitive.Geometry
oPnts = oGeo.Points
aPos = oPnts.PositionArray
aPos = [list(aPos[0]),list(aPos[1]),list(aPos[2])]
v = XSIMath.CreateVector3()
m = XSIMath.CreateMatrix4()
oTrans = oObj.Kinematics.Global.Transform
oTrans.GetMatrix4(m)
for i in range(oPnts.Count):
if activePoints[i]:
v.Set(aPos[0][i],aPos[1][i],aPos[2][i])
v.MulByMatrix4InPlace(m)
aPos[0][i] = v.X
aPos[1][i] = v.Y
aPos[2][i] = v.Z
return aPos
#------------------------------
# getSmp2Pnt
#------------------------------
def getSmp2Pnt(oGeo):
smp2pnt = []
oSmps = oGeo.Samples
oPnts = oGeo.Points
for i in oSmps:
smp2pnt.append(-1)
for oPnt in oPnts:
for smp in oPnt.Samples:
smp2pnt[smp.Index] = oPnt.Index
return smp2pnt
#------------------------------
# getActivePoints
#------------------------------
def getActivePoints(nbPnts,smp2pnt,oSmpIDs):
activePnts = []
for i in range(nbPnts):
activePnts.append(False)
for i in oSmpIDs:
activePnts[ smp2pnt [ i ] ] = True
return activePnts
#------------------------------
# getDistanceArray
#------------------------------
def getDistanceArray(gradientType,nbPnts,p1,p2,aPos,activePoints):
distanceArray = []
for i in range(nbPnts):
distanceArray.append( -1.0 )
v = XSIMath.CreateVector3()
if gradientType == 0: #Linear Plane to Point
n = XSIMath.CreateVector3()
n.Sub(p2,p1)
n.NormalizeInPlace()
for i in range(nbPnts):
if activePoints[i]:
v.Set(aPos[0][i],aPos[1][i],aPos[2][i])
v.SubInPlace(p1)
len = v.Dot( n )
#log(len)
distanceArray[i] = abs( len )
if gradientType == 1: # Distance
for i in range(nbPnts):
if activePoints[i]:
v.Set(aPos[0][i],aPos[1][i],aPos[2][i])
v.SubInPlace(p1)
#log(v.Length())
distanceArray[i] = v.Length()
return distanceArray
#------------------------------
# getDistanceArray
#------------------------------
def getPercentage(nbPnts,p1,p2,distanceArray,activePoints):
percentageArray =[]
for i in range(nbPnts):
percentageArray.append(100)
p1.SubInPlace(p2)
length = p1.Length()
if length == 0:
log("Plz Select2Pnt")
return
for i in range(nbPnts):
if activePoints[i]:
per = abs( distanceArray[i]/ length * 100 )
if per > 100:
per = 100
per = 100 - per
#log(per)
percentageArray[i] = per
return percentageArray
#------------------------------
# perArrayToFCurvePerArray
#------------------------------
def perArrayToFCurvePerArray(percentageArray):
fc = PPG.FCurve.Value
for i,per in enumerate( percentageArray ):
percentageArray[i] = 100 - ( minmax( fc.Eval( per ) ) * 100 )
return percentageArray
#------------------------------
# gradationExe
#------------------------------
def gradationExe(rePaint):
gradientType = PPG.GraForm.Value
gradientColorType = PPG.GraColorPattern.Value
gToPntSmps = PPG.ToPntSamples.Value
#Color
c1 = [PPG.FCurve1_red.Value,
PPG.FCurve1_green.Value,
PPG.FCurve1_bule.Value,
PPG.FCurve1_alpha.Value]
c2 = [PPG.FCurve2_red.Value,
PPG.FCurve2_green.Value,
PPG.FCurve2_bule.Value,
PPG.FCurve2_alpha.Value]
#Position
if rePaint:
p1 = XSIMath.CreateVector3()
p1.Set(
PPG.aPosX.Value,
PPG.aPosY.Value,
PPG.aPosZ.Value )
p2 = XSIMath.CreateVector3()
p2.Set(
PPG.bPosX.Value,
PPG.bPosY.Value,
PPG.bPosZ.Value )
else:
p1 = pickPosition()
if p1 == -1:
return
PPG.aPosX.Value = p1.X
PPG.aPosY.Value = p1.Y
PPG.aPosZ.Value = p1.Z
p2 = pickPosition()
if p2 == -1:
return
PPG.bPosX.Value = p2.X
PPG.bPosY.Value = p2.Y
PPG.bPosZ.Value = p2.Z
oSels = app.Selection
for oSel in oSels:
oSmpIDs = getSelectSampleIDs(oSel,gToPntSmps)
if oSmpIDs == -1:
continue
if oSel.Type != "polymsh":
oSub = oSel.SubComponent
oObj = oSub.Parent3DObject
else:
oObj = oSel
oGeo = oObj.ActivePrimitive.Geometry
oPnts = oGeo.Points
nbPnts = oPnts.Count
smp2pnt = getSmp2Pnt(oGeo)
activePoints = getActivePoints(nbPnts,smp2pnt,oSmpIDs)
aPos = getGlobalPntsPositions(oObj,activePoints)
distanceArray = getDistanceArray(gradientType,nbPnts,p1,p2,aPos,activePoints)
percentageArray = getPercentage(nbPnts,p1,p2,distanceArray,activePoints)
percentageArray = perArrayToFCurvePerArray(percentageArray)
Clusters = oGeo.Clusters.Filter("sample")
for Cls in Clusters:
for oProp in Cls.Properties:
if(oProp.Name == "Vertex_Color"):
aVC = oProp.Elements.Array
aVC = [list(aVC[0]),list(aVC[1]),list(aVC[2]),list(aVC[3])]
#Normal
if PPG.GraComposition.Value == 0:
#Color1 > Bace
if gradientColorType == 0:
for i in oSmpIDs:
r = getMixPercentage( c1[0],aVC[0][i],percentageArray[smp2pnt[i]])
g = getMixPercentage( c1[1],aVC[1][i],percentageArray[smp2pnt[i]])
b = getMixPercentage( c1[2],aVC[2][i],percentageArray[smp2pnt[i]])
a = getMixPercentage( c1[3],aVC[3][i],percentageArray[smp2pnt[i]])
aVC[0][i] = getMixPercentage( r, aVC[0][i], PPG.Percent.Value )
aVC[1][i] = getMixPercentage( g, aVC[1][i], PPG.Percent.Value )
aVC[2][i] = getMixPercentage( b, aVC[2][i], PPG.Percent.Value )
aVC[3][i] = getMixPercentage( a, aVC[3][i], PPG.Percent.Value )
#Color1 > Color2
if gradientColorType == 1:
for i in oSmpIDs:
r = getMixPercentage( c1[0], c2[0], percentageArray[smp2pnt[i]])
g = getMixPercentage( c1[1], c2[1], percentageArray[smp2pnt[i]])
b = getMixPercentage( c1[2], c2[2], percentageArray[smp2pnt[i]])
a = getMixPercentage( c1[3], c2[3], percentageArray[smp2pnt[i]])
aVC[0][i] = getMixPercentage( r, aVC[0][i], PPG.Percent.Value )
aVC[1][i] = getMixPercentage( g, aVC[1][i], PPG.Percent.Value )
aVC[2][i] = getMixPercentage( b, aVC[2][i], PPG.Percent.Value )
aVC[3][i] = getMixPercentage( a, aVC[3][i], PPG.Percent.Value )
#Multiple
if PPG.GraComposition.Value == 1:
#Color1 > Bace
if gradientColorType == 0:
for i in oSmpIDs:
#r = getMixPercentage( c1[0],aVC[0][i],percentageArray[smp2pnt[i]])
#g = getMixPercentage( c1[1],aVC[1][i],percentageArray[smp2pnt[i]])
#b = getMixPercentage( c1[2],aVC[2][i],percentageArray[smp2pnt[i]])
#a = getMixPercentage( c1[3],aVC[3][i],percentageArray[smp2pnt[i]])
r = getMixPercentage( c1[0],1,percentageArray[smp2pnt[i]])
g = getMixPercentage( c1[1],1,percentageArray[smp2pnt[i]])
b = getMixPercentage( c1[2],1,percentageArray[smp2pnt[i]])
a = getMixPercentage( c1[3],1,percentageArray[smp2pnt[i]])
r = scalerMultiple(r,aVC[0][i])
g = scalerMultiple(g,aVC[1][i])
b = scalerMultiple(b,aVC[2][i])
a = scalerMultiple(a,aVC[3][i])
aVC[0][i] = getMixPercentage( r, aVC[0][i], PPG.Percent.Value )
aVC[1][i] = getMixPercentage( g, aVC[1][i], PPG.Percent.Value )
aVC[2][i] = getMixPercentage( b, aVC[2][i], PPG.Percent.Value )
aVC[3][i] = getMixPercentage( a, aVC[3][i], PPG.Percent.Value )
#Color1 > Color2
if gradientColorType == 1:
for i in oSmpIDs:
r = getMixPercentage( c1[0], c2[0], percentageArray[smp2pnt[i]])
g = getMixPercentage( c1[1], c2[1], percentageArray[smp2pnt[i]])
b = getMixPercentage( c1[2], c2[2], percentageArray[smp2pnt[i]])
a = getMixPercentage( c1[3], c2[3], percentageArray[smp2pnt[i]])
r = minmax( scalerMultiple(r,aVC[0][i]) )
g = minmax( scalerMultiple(g,aVC[1][i]) )
b = minmax( scalerMultiple(b,aVC[2][i]) )
a = minmax( scalerMultiple(a,aVC[3][i]) )
aVC[0][i] = getMixPercentage( r, aVC[0][i], PPG.Percent.Value )
aVC[1][i] = getMixPercentage( g, aVC[1][i], PPG.Percent.Value )
aVC[2][i] = getMixPercentage( b, aVC[2][i], PPG.Percent.Value )
aVC[3][i] = getMixPercentage( a, aVC[3][i], PPG.Percent.Value )
oProp.Elements.Array = aVC
#------------------------------
def Gradation_Exe_OnClicked():
gradationExe(False)
#------------------------------
def RePaint_OnClicked():
log("RePaint")
gradationExe(True)
"""
def main():
cp = XSIFactory.CreateObject("CustomProperty")
cp.Name = "VertexColorTools"
colorList = ["Set","UpperLayer","Math"]
addColorParam(cp,colorList)
addOtherParam(cp)
FCurveColorList = ["FCurve1","FCurve2"]
addColorParam(cp,FCurveColorList)
oly = createLayout(cp,colorList,FCurveColorList)
lyLogic(oly)
app.InspectObj(cp,"","",3)
main()