'----------------------------------------------------------------- 'MakeTail_Support.vbs 'Tail一括作成ツール 'by_tyotyo XSI徒然日記 http://paradisebrain.seesaa.net/article/106476811.html ' '2008/09/13 '----------------------------------------------------------------- 'on error resume next dim Sel set Sel = getvalue("SelectionList") MakeTail_Support_main Sel,10,true,true,true,"",1 '引数は入力のデフォルト値 function MakeTail_Support_main(GuideObjects,boneNum,simOff,Reset,makeShadow,prefix,IconSize) dim tmp,flag,allCrv,MBFlag dim i,j,LoopCount i=0 LoopCount = 0 dim madeTail,TailEff,TailRoot dim cnsRoot,cnsEff,cnsRootCPS,model dim Group_plot,Group_cns flag = MakeTail_Support_inputValue(bonenum,simOff,Reset,makeShadow,prefix,IconSize) MBFlag = 0 if not(flag) and GuideObjects.count > 1 then allCrv=true for each oObj in GuideObjects if not(oObj.type = "crvlist") then allCrv = false next if allCrv = true then MBFlag = MsgBox("選択が全部カーブです。一括処理しますか?", 3) end if end if if MBFlag = 6 then LoopCount = GuideObjects.count - 1 end if if not(flag) and (MBFlag = 0 or MBFlag = 6 or MBFlag = 7) then 'サイクルチェックの無効 dim cycleCheck cycleCheck = GetValue("preferences.data_management.disable_cycle_checking") SetValue "preferences.data_management.disable_cycle_checking", true for j = 0 to LoopCount DeselectAll Model = GuideObjects(0).model if MBFlag = 6 then Model = GuideObjects(j).model end if 'Tail作成-------------------------------------------------- if MBFlag = 6 then set madeTail = MakeTail( ,GuideObjects(j), boneNum) else set madeTail = MakeTail( ,GuideObjects, boneNum) end if ' DumpTail madeTail Madetail.Root.name = prefix & Madetail.Root.name for each oObj in Madetail.Root.FindChildren oObj.name = prefix & oObj.name next redim TailCtrl(madeTail.nbPoints - 2) i=0 for each oObj in MadeTail.hidden if instr(oObj.name,lCase("tailctrl_upv")) > 0 then set TailCtrl(i) = oObj.Parent i=i+1 end if next '変数に入れとく---------------------------------------------------------------------------------------------------- redim TailBone(selection.count - 3) i=0 for each oObj in Selection if oObj.type = "bone" then set TailBone(i) = oObj i=i+1 end if next set TailRoot = selection(0) set TailEff = selection(2) 'ボーン作成===== redim cnsBone(selection.count - 3) redim twistnull(selection.count - 3) redim ShadowNull(selection.count - 3) set cnsRoot = Create3DSkeleton(0,0,0, 0,1,0, 0,0,1,cnsBone(0),cnsEff) If not(Model = ActiveSceneRoot) then ParentObj model ,cnsRoot AddProp "Custom_parameter_list", cnsRoot , , "DisplayInfo",cnsRootCPS SIAddCustomParameter cnsRootCPS, "cns_Mute", SIBool,false,,, , 5 SIAddCustomParameter cnsRootCPS, "cns_Ori", SIBool,false,,, , 5 SIAddCustomParameter cnsRootCPS, "IconSize",SIDouble,IconSize,0.01,10000,,5,0.01,100 SetValue cnsRoot & ".root.primary_icon", 0 SetValue cnsEff & ".eff.primary_icon", 0 'ボーン追加とか===== for i=1 to UBound(TailBone) set cnsBone(i) = AppendBone(cnsEff,0,i+1,0) next cnsRoot.name = TailRoot.name & "_cns" for i = 0 to Ubound(cnsbone) cnsBone(i).name = TailBone(i).name & "_cns" setValue cnsBone(i) & ".bone.primary_icon",0 next cnsEff.name = TailEff.name & "_cns" for i=0 to UBound(TailBone) setvalue cnsBone(i)&".bone.length",getvalue(TailBone(i) & ".bone.length") set twistnull(i) = CreateTwistNull(1,cnsBone(i))'ツイストヌル生成 setvalue twistnull(i) & ".null.primary_icon", 0 if makeShadow = true then'エンベロープ用ヌル追加 set ShadowNull(i) = getprim("Null",TailBone(i).name & "_env",Model) ApplyCns "Pose", ShadowNull(i)&" ",twistnull(i)&" " setvalue ShadowNull(i) & ".null.primary_icon", 2 setvalue ShadowNull(i) & ".null.size", Iconsize / 3 if i > 0 then ParentObj ShadowNull(i-1) ,ShadowNull(i) end if end if next ApplyCns "Position", cnsRoot&" ", tailRoot&" " MatchTransform cnsroot, tailroot, siTrn for i=0 to UBound(TailBone) ApplyCns "Orientation", cnsbone(i)&" ", tailBone(i)&" " ApplyCns "Position", cnsbone(i)&" ", tailBone(i)&" " addExpr cnsbone(i) & ".kine.poscns.active","cond(" & cnsRoot & ".DisplayInfo.cns_Mute == false && " & cnsRoot & ".DisplayInfo.cns_Ori == false , true , false )" addExpr cnsbone(i) & ".kine.oricns.active","cond(" & cnsRoot & ".DisplayInfo.cns_Mute == false && " & cnsRoot & ".DisplayInfo.cns_Ori == true , true , false )" next ApplyCns "Position", cnsEff&" ", tailEff&" " addExpr cnsEff & ".kine.poscns.active","cond(" & cnsRoot & ".DisplayInfo.cns_Mute == false && " & cnsRoot & ".DisplayInfo.cns_Ori == false , true , false )" 'ミュート・ニュートラルポーズのリセット---------------------------------------------------------------------------------------------------- AlignRootToFirstBone cnsRoot if simOff = true then RemoveAnimation madeTail.ControlChains(2) & ".kine.global.Spring.Mute" SetValue madeTail.ControlChains(2) & ".kine.global.Spring.Mute", True end if if reset = true then SetNeutralPose madeTail.Root, siSRT, True 'マーキングセット----------------------------------------------------------------------------------------------------- AddProp "Custom_parameter_list",CnsRoot,,"MarkingSet",tmp AddProxyParam tmp,CnsRoot & ".kine.local.rotx" AddProxyParam tmp,CnsRoot & ".kine.local.roty" AddProxyParam tmp,CnsRoot & ".kine.local.rotz" AddProxyParam tmp,CnsRoot & ".kine.local.posx" AddProxyParam tmp,CnsRoot & ".kine.local.posy" AddProxyParam tmp,CnsRoot & ".kine.local.posz" for each oObj in cnsBone AddProp "Custom_parameter_list",oObj,,"MarkingSet",tmp AddProxyParam tmp,oObj & ".kine.local.rotx" AddProxyParam tmp,oObj & ".kine.local.roty" AddProxyParam tmp,oObj & ".kine.local.rotz" AddProxyParam tmp,oObj & ".DisplayInfo_twist.twist" next '------------グループ化--------------- dim Gstr Gstr = join(cnsBone,",") Gstr = Gstr & "," & cnsRoot CopyPaste CreateGroup(prefix & "Tail_Plot",Gstr), , Model, 1 set tmp = CreateGroup(prefix & "Tail_Hide",madeTail.hidden) CopyPaste tmp, , Model, 1 AddToGroup tmp , tailRoot & "," & tailEff ToggleVisibility tmp.Members ToggleVisibility tmp '------------アイコンサイズのエクスプレッション------------------ for each oObj in tailBone setShadowIconExp oObj,cnsRootCPS&".IconSize * 0.5" ,1 next for each oObj in cnsBone setShadowIconExp oObj,cnsRootCPS&".IconSize * 0.7" ,6 next for each oObj in TwistNull setShadowIconExp oObj,cnsRootCPS&".IconSize * 0.3" ,4 next setShadowIconExp MadeTail.Root,cnsRootCPS&".IconSize * 1.5" ,4 setShadowIconExp cnsRoot,cnsRootCPS&".IconSize * 1.3" ,4 setShadowIconExp cnsEff,cnsRootCPS&".IconSize * 0.5" ,1 dim bx1,bx2 getBBox TailCtrl(0), true,bx1,,,bx2 for each oObj in TailCtrl setvalue oObj & ".kine.local.sclx" , 1/abs(bx2 - bx1) * (getvalue(cnsRootCPS & ".IconSize") * 0.8) setvalue oObj & ".kine.local.scly" , 1/abs(bx2 - bx1) * (getvalue(cnsRootCPS & ".IconSize") * 0.8) setvalue oObj & ".kine.local.sclz" , 1/abs(bx2 - bx1) * (getvalue(cnsRootCPS & ".IconSize") * 0.8) ResetTransform oObj, siCtr, siScl, siXYZ AddExpr oObj & ".visibility.rendvis"," False" 'レンダリング切っとく next '----------------------------------------------------------------------------------------------------- next 'サイクルチェックの設定を戻しとく SetValue "preferences.data_management.disable_cycle_checking", cycleCheck end if MakeTail_Support_main = true end function '==================================================================================================================================== '==================================================================================================================================== '==================================================================================================================================== function MakeTail_Support_inputValue(outBoneNum,outSimOff,outReset,outShadow,outPrefix,outIconSize) dim out dim inputCPS AddProp "Custom_parameter_list", ActiveProject.ActiveScene.root , , "InputValue",inputCPS SIAddCustomParameter inputCPS, "bone_number", siInt4,outBoneNum,2,10000, , 5,2,50 SIAddCustomParameter inputCPS, "off", SIBool,outSimOff,,,, 5,,,"第1エフェクタのシミュレーションをミュート" SIAddCustomParameter inputCPS, "reset", SIBool,outReset,,,, 5,,,"ルートのニュートラルポーズのリセット" SIAddCustomParameter inputCPS, "makeShadow", SIBool,outShadow,,,, 5,,,"デフォーマー用のヌル生成" SIAddCustomParameter inputCPS, "prefix", siString,outPrefix,,,, 5,,,"接頭語" SIAddCustomParameter inputCPS, "IconSize", siDouble,outIconSize,0.01,100,, 5,,,"アイコンサイズ" out = InspectObj( inputCPS, , "TailMaker", 4,false) outBoneNum = getvalue(inputCPS & ".bone_number") outSimOff = getvalue(inputCPS & ".off") outReset = getvalue(inputCPS & ".reset") outShadow = getvalue(inputCPS & ".makeShadow") outPrefix = getvalue(inputCPS & ".prefix") outIconSize = getvalue(inputCPS & ".IconSize") deleteObj inputCPS MakeTail_Support_inputValue = out end function function DumpTail(inTail) logmessage "Data in the tail object:" logmessage "------------------------" logmessage "Nb Points : " & inTail.nbPoints logmessage "Control Chains: " & inTail.ControlChains logmessage "Control Root : " & inTail.Root logmessage "Trace Chain : " & inTail.TraceChain logmessage "Trace Root : " & inTail.TraceRoot logmessage "Hidden : " & inTail.Hidden logmessage "Envelope : " & inTail.Envelope ' logmessage "Shadow Start : " & inTail.ShadowStart ' logmessage "Shadow Ends : " & inTail.ShadowEnds ' logmessage "Shadow Objects: " & inTail.Shadows end function function CreateTwistNull(inPos,inObj) Dim getnull Dim bonelength Dim getPset bonelength = GetValue (inObj & ".bone.length") 'ヌル生成したり位置を親と重ねたり set getnull = GetPrim( "Null", inObj.name & "_twist" , inObj) ResetTransform ,siObj, siSRT, siXYZ if inPos = 0 then SetValue getnull & ".kine.local.posx", 0 'ボーンと同じ場所に移動 if inPos = 1 then SetValue getnull & ".kine.local.posx", bonelength / 2 'ボーンの真ん中に移動 if inPos = 2 then SetValue getnull & ".kine.local.posx", bonelength 'ボーンの終端に移動 '親にパラメーター追加したりエクスプレッション設定したり set madeParam = AddProp ("Custom_parameter_list",inObj , , "DisplayInfo_twist",getPset) 'カスタムパラメーターセット生成 SIAddCustomParameter getPset, "twist", siDouble, 0, -3600, 3600, , 5, -36000, 36000 '生成したセットにカスタムP生成 CopyPaste getPset & ".twist", , getnull & ".kine.local.rotx" , 1 '回転をカスタムPにエクスプレッション set CreateTwistNull = getNull end function sub setShadowIconExp(TargetObj,inExp,Shape) if lcase(TargetObj.type) = "root" or lcase(TargetObj.type) = "bone" or lcase(TargetObj.type) = "eff" then if not(lcase(TargetObj.type) = "bone") then addExpr TargetObj & "."& TargetObj.type & ".shadow_scaleX",inExp addExpr TargetObj & "."& TargetObj.type & ".radius",inExp addExpr TargetObj & "."& TargetObj.type & ".shadow_scaleZ",inExp setValue TargetObj & "."& TargetObj.type & ".shadow_icon",Shape else addExpr TargetObj & ".null.shadow_scaleX",inExp addExpr TargetObj & ".null.shadow_scaleY",inExp addExpr TargetObj & ".null.shadow_scaleZ",inExp setValue TargetObj & "."& TargetObj.type & ".shadow_icon",Shape end if end sub