2015年2月26日木曜日

円上にあつめる


Houdiniのチュートリアルで、
ポイントを円状に整列する
VOPSOP(ICEみたいなもの)があったので、
SI(Python)で確認してみた
確認しただけでコードは屑ですのであしからず

SIにはプラグインがあるので、
それを利用すればいいんだけどね
mx_Roundish

手順

1.中心点の作成
今回はBBOXを作成した

2.平面化する
(平面化で無い場合は球になります)


3.同距離に収める

・中心から、選択ポイントのベクトルを作成
・ベクトルをノーマライズ
・半径を掛ける
・中心とベクトルを足す

の順、スクリプトは
いろいろ適当なことやってるけど、
こんな感じ。

Houdiniはすでに平面状のポイントをそろえる
サンプルだったけど、

平面じゃなければ、平面化すれば良いんじゃね?
ってことで確認してみた

最初に平面化するのが味噌だったのか。

実作業としては、等間隔に収めたいと思います
円周でのソートは今後の課題ですな


追記
ぐぐったらコードをはけん。
二つのベクトルがわかってればAtan2で角度がでるので、
それで、比較してるんですな。
座標を平面座標に変換する必要がありそうだけど。
すでに並んでいるから問題ないのかな?

3点の座標から簡単に角度と回転方向を求める. (2・3・N次元,外積を用いる方法)

この辺りも覚えておきたい所

近況

Houdiniの勉強をしてるんだけど、

・必要そうな機能を洗い出し>習得

と言うわけにはいかないっぽい。
前提条件がノードだし、
データの扱いは特殊だし
(普通のモデリングソフトとはいかない)

リアルタイムの扱いは少ないし

基本、チュートリアルをやってみて、
何が出来るか把握してからじゃないと
工程の途中で詰んでしまいます orz

かと言って
歴史は長いのでチュートリアルは多いし

今回みたいに応用の利く技術が多いので、
幅は広がりそうですね

プロシージャルモデリングのように
あとでジワジワ利くタイプです


■最近買った本
・Maya実戦 ハードサーフェースモデリング
・ウェザリングの教科書
・背景CG実戦テクニック

背景充

どの本もお値段以上の良本でした(吐血 orz

2015年2月11日水曜日

Softimage Script : VCTool(Softimage用、頂点カラー塗りツール)

背景用の頂点カラーツールです

開発途中で、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()

2015年2月9日月曜日

MAYA Plugin : AlignPlaneManip

指定のベクトルで平面に揃えたいじゃないですかーーー

SIのスクリプトは作ったのですが。

MoriさんがMAYA + C++ で作っておられ、
さらにGitでの公開での太っ腹っぷり。

それは参考にしますよ :p
こちら


いま、ちょっと時間が足りないけど

Memo : エフェクトとか、スライドとか

絶賛背景修羅場中

メインはSIだけど、
SpeedTree使ったり、
SubstanceDesignerつかったり。

ソフトになれて来て時間の短縮が可能になった分
クオリティが上がってると信じたい。

※だけど手書きの質感が一番好きです




エフェクトについてのスライド

関西CEDECのせい?
有用な情報がたくさん



以前から気になってたハイエンドゲームへのテクニック。

あるある
エフェクトは半透明をどうするかの問題において、
イロイロ制約がおおいんだよね orz




UE4本を買ってみたのでUnityと比較してみます。
はっきり言ってUnityでのエフェクト制作は制限があってきついです。
まあ、勉強になります。
シェーダーとかのな!!!




おおお、これ自分がHoudini Indieを買った理由、
コレがしたいんですよ・・・。
エフェクトについてはSIからHoudiniに移行したい所




できれば〜
やっぱお金があると、新しいマシンが買えて余裕も出るよね・・・的な。

2015年2月4日水曜日

Photoshop CC 2014のカスタムパネルの制作 1

Photoshop cc2014 ExtentionBuilder3.md—/Users/kawabata_imac/Dropbox/Blog/Photoshop

Photoshop CC 2014 から
Flashを利用したカスタムパレットの
サポートが無くなりました

パレットを簡単に作れていたツール
Adobe Configurator 4
利用出来なくなりましたが

CC 2014 でもボタンスクリプトまで出来ましたのでメモ

Adobe Extension Builder 3

Adobe Configurator and deprecated Flash-based panel support in Adobe CC products

Adobe Extantion Builder 3
を使えば開発が出来るようです

Extention Builder 3を
導入してみる事にします

OS環境

  • Microsoft® Windows® 7 (32-bit and 64-bit)
  • Microsoft Windows 8 (32-bit and 64-bit)
  • Mac OS® X v10.7 or higher

が、サポートされてるようです

開発環境

  • Eclipse 3.6 or higher

Eclipsという統合開発環境が必用なようです

実行環境

  • MACOSX 10.8
  • MACOSX 10.8 Windows8.1 64bit Parallels Ecripse 3.6
  • Windows7 Pro 64bit

三つの環境で試してみました

ここでは、Windowsの導入をしてみます

Adobe Extension Builder 3

Adobe Lab
上記のサイトに接続します。
下部の方に導入方法があります

導入方法

  1. Eclipse
    DOWNLOADS > Eclipse IDE for Java Developers
    を選択してDL、インストール

  2. Download Adobe Extension Builder 3
    Download Extension Builder 3をDLします
    展開しなくてOK

  3. eclipseのインストールと環境の整備
    eclipseはDLし、解凍すれば起動出来るのですが、
    いくつかの環境設定が必用です

立ち上がらない場合は以下の二つを確認してください

JAVAのSDK

MACの場合は要求されなかったですが、
Windowsの場合は
JAVAのSDK環境が必用です。
JDKのVerは1.6を要求してるのでこちらより
jdk-6u45-windows-x64.exe をDLインストールします

Pathを通す

フォルダ内の eclipse.ini
ファイルをテキストエディタ等でひらき
-vmargs の前に
-vm "JDKのPath" を追加すればOKです


-vm
C:\Program Files\Java\jdk1.6.0_45\bin\javaw.exe

これで起動するか確認してください

-参考-
Eclipse 起動時に使用する Java VM を指定する

4.ecripseを立ち上げ、 Help > Install New Software. > Add
ボタンを押し、DL済みの
"extensionbuilder_p3_080113.zip"
を選択します

5.Adobe Extension Builder 3をチェック

6.Next > を押しつつ進める(途中でライセンス規約あり)

7.eclipseの再起動を促されるので再起動します

ここまでで、インストールの作業は終了です

-参考-
extensionbuilder3 のリリースノート PDF

環境を Adobe Extantion Builderに

eclipseは統合開発環境ですので、
Extantion Builder に開発環境を設定します

  1. 立ち上げると Welcom メニューがあるので、それを"X"で閉じる

  2. Window > Open Perspective > Other より
    Adobe Extantion Builder 3を選択

環境を cc から cc 2014に

2015 2月現在の環境は CC が前提です。
これを現在の最新Verの CC 2014 に適用させます

  1. ターゲットアプリの変更

window > preferences より
Adobe Extenstion Builder 3 > CC Launching Paths > Target Application
これをPhotoshop CC 2014 に変更しました

2. 出力先のフォルダの変更

window > preferences より
Adobe Extenstion Builder 3 > CC Launching Paths > Sevice Maneger

Photoshop CC
C:\Program Files (x86)\Common Files\Adobe\CEPServiceManager4
C:\Users\Username\AppData\Roaming\Adobe\CEPServiceManager4

Photoshop CC 2014
C:\Program Files (x86)\Common Files\Adobe\CEP
C:\Users\Username\AppData\Roaming\Adobe\CEP

CC2014に変更してください

CEPフォルダが無い場合は 上記の2カ所に "CEP" フォルダを制作してください

  1. プロジェクトを作成します 適当にプロジェクトを作成します

  2. プロジェクトのVerを指定する
    書き出すXMLのVerが CC のままになっております。
    これを CC 2014 に変更します

プロジェクトを右クリック > Adobe Extention Builder 3 >
Bundle Manifest Editor >
Manifest.xml タブを選択 >
コード内で右クリック > Open Withでテキストエディターで開いて編集します

こちらを

Photoshop cc
            <Host Name="PHXS" Version="[14.0,14.9]" />
            <Host Name="PHSP" Version="[14.0,14.9]" />

            <RequiredRuntime Name="CSXS" Version="4.0" />

これに変更します

Photoshop cc 2014
            <Host Name="PHXS" Version="[15.0,15.9]" />
            <Host Name="PHSP" Version="[15.0,15.9]" />

            <RequiredRuntime Name="CSXS" Version="5.0" />

レジストリの変更

セキュリティの関係か、Adobeが許可したものでないと
Extantionは読み込まれません

これはDebugモードにすることで変更できます、
レジストリを変更します
Win: regedit > HKEY_CURRENT_USER/Software/Adobe/CSXS.5 右クリックから 新規 > 文字列値
で名前を変更し、値を設定します

文字列 : PlayerDebugMode
 : 1

環境設定
Adobe Extension Builder and Creative Cloud 2014

制作してみる

Ranしてみます
問題が無ければ PhotoshopCC 2014 が立ち上がります
Extentionから、Demoを選択

ボタンを押してみると
Hellow Photoshop
ダイアログが表示されます。

これで開発環境は構築出来ました

ここからの制作が大変そうですが、
とりあえず、今回はココまでにしとうございます orz

最後にフォーラムを見てねって感じ Forum

感想

espliseをインストールしないと行けないので難易度が上がった印象。
レジストリの変更とか難易度高すぎ

espliseをインストールしなくても
作成は出来るみたい(さらに高難易度?

HTML5になったことで、
Flash依存しないというのは良いかもしれないけど。

まあ、どのみち勉強はしないとダメね

メモ

  • Eclipse : オープンソースの、IBMの開発統合環境ツール

  • Runで出力される位置
    これが CC 2014 では
    C:\Users\Username\AppData\Roaming\Adobe\CEPServiceManager4\extensions\ C:\Users\Username\AppData\Roaming\Adobe\CEP\extensions\ となるみたい。ハマった

参考サイト

CEPガイド7:エクステンションのパッケージと配布
CCツールEXTENSIONをHTML5で作る Extension Builder 3のインストール
Adobe Extension Builder 3でCC 2014用の拡張開発環境を構築