'----------------------------------------------------------------- 'Make_Snake_Spine.vbs ' ' '2008/03/25 '----------------------------------------------------------------- 'on error resume next '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= '入力用変数 dim ctrlNum 'パスコントローラーの数:4以上 dim defaultLength '長さ:>0 dim deformerNum 'デフォーマーの数:2以上 dim IconSize 'コントロールアイコンの大きさの基準:>0 dim handleNum '回転ハンドルの数:2以上 dim onPathMode 'パス位置相対値(0~1)指定 dim stretchMode 'ストレッチモード指定 dim VerShearMaking '縦シヤー変形指定 dim BulgeMaking 'バルジ変形指定 dim ShadowRigMaking 'シャドウリグ生成指定 dim makeFromCrv '選択カーブから生成 'デフォルト値 ctrlNum = 5 defaultLength = 10 deformerNum = 10 IconSize = 1.5 handleNum = 2 onPathMode = True stretchMode = false VerShearMaking = true BulgeMaking = true ShadowRigMaking = true makeFromCrv = false 'その他グローバル変数 dim cycleCheck dim selectedCrv dim grobalSRT dim bodyPath , bodyPath_CPS '_CPS:カスタムパラメーターセット dim bodyCrv dim CtrlNull , CtrlNull_CPS dim upVBone,root_CPS dim upVBonePin dim Vertebra , Vertebra_CPS dim handle dim handleGrobalRot,handleGrobalRot_CPS dim handleUpV dim rootCns,rootCns_CPS dim ShadowRig,ShadowRigSRT dim VerShear,VerShear_CPS dim P_CrvShear,P_CrvShear_CPS dim BulgeCtrl,BulgeCtrl_CPS dim VertebraBulge,VertebraBulge_CPS dim P_CrvBulge,P_CrvBulge_CPS dim CtrlGroupList dim HideGroupList dim EnvelopeGroupList dim ModelNull '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= if inputValue=false then'数値入力 'dim start 'start = time 'サイクルチェックの無効 cycleCheck = GetValue("preferences.data_management.disable_cycle_checking") SetValue "preferences.data_management.disable_cycle_checking", True set grobalSRT = GetPrim("Null","SnakeSpine_SRT") makeBodyPath 'body_path生成(bodyPath) makeCtrlNull 'コントローラー生成(CtrlNull) makebodyCrv 'body_crv生成() makeUpVBonePin 'ボーンのピン生成(upVBonePin) makeUpVBone 'アップベクタ用のボーン生成(upVBone) setBoneStretchCns 'ボーンをピンにストレッチ&コンストレイントさせる makeSnakeVertebra '背骨生成(Vertebra) makeUpVHandle 'Handle生成・upVHandleにエクスプレッション if VerShearMaking then makeVerticalShearCtrl 'たわみコントローラー生成 if BulgeMaking then makeBulgeCtrl 'バルジコントローラー生成 if ShadowRigMaking then makeShadowRig 'シャドウリグ生成 ParentInOrder '階層整理・グループ作成 logmessage ModelNull SetValue "preferences.data_management.disable_cycle_checking", cycleCheck'サイクルチェックの設定を戻しとく 'logmessage "Time : "& datediff("s", start, time) end if ' '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ' '--------------------------------------------------------------- '数値入力 '--------------------------------------------------------------- function inputValue dim out dim inputCPS Set oSelection = GetValue( "SelectionList" ) if selection.count>0 then if oSelection(0).type = "crvlist" then set selectedCrv = oSelection(0) makeFromCrv=true end if end if AddProp "Custom_parameter_list", ActiveProject.ActiveScene.root , , "InputValue",inputCPS if makeFromCrv then SIAddCustomParameter inputCPS, "inmakeFromCrv" , siBool ,makeFromCrv ,0 ,1 , , 5, , ,"選択カーブから作成" SIAddCustomParameter inputCPS, "inCtrlNum" , siInt4 ,ctrlNum ,3 ,10000 , , 5,3 ,20 ,"コントローラー数" SIAddCustomParameter inputCPS, "inDefaultLength" , siDouble ,defaultLength ,0.001 ,10000 , , 5,1 ,100,"長さ" SIAddCustomParameter inputCPS, "indeformerNum" , siInt4 ,deformerNum ,2 ,10000 , , 5,2 ,100,"デフォーマーの数" SIAddCustomParameter inputCPS, "inIconSize" , siDouble ,IconSize ,0.001 ,10000 , , 5,0.01 ,10 ,"コントロールアイコンのサイズ" SIAddCustomParameter inputCPS, "inhandleNum" , siInt4 ,handleNum ,2 ,10000 , , 5,2 ,10 ,"捻りハンドルの数" SIAddCustomParameter inputCPS, "inOnPathMode" , siBool ,onPathMode ,0 ,1 , , 5, , ,"パス位置相対値指定(0~1)" SIAddCustomParameter inputCPS, "inStretchMode" , siBool ,stretchMode ,0 ,1 , , 5, , ,"ストレッチモード" SIAddCustomParameter inputCPS, "inVerShearMaking" , siBool ,VerShearMaking ,0 ,1 , , 5, , ,"縦シヤー変形コントローラー生成" SIAddCustomParameter inputCPS, "inBulgeMaking" , siBool ,BulgeMaking ,0 ,1 , , 5, , ,"バルジ変形コントローラー生成" SIAddCustomParameter inputCPS, "inShadowRigMaking" , siBool ,ShadowRigMaking,0 ,1 , , 5, , ,"シャドウリグ生成" out = InspectObj( inputCPS, , "MakeSnakeSpine", 4,false) if makeFromCrv then makeFromCrv =getvalue(inputCPS & ".inmakeFromCrv") ctrlNum =getvalue(inputCPS & ".inctrlNum") defaultLength =getvalue(inputCPS & ".indefaultLength") deformerNum =getvalue(inputCPS & ".indeformerNum") IconSize =getvalue(inputCPS & ".inIconSize") handleNum =getvalue(inputCPS & ".inhandleNum") onPathMode =getvalue(inputCPS & ".inonPathMode") stretchMode =getvalue(inputCPS & ".inStretchMode") VerShearMaking =getvalue(inputCPS & ".inVerShearMaking") BulgeMaking =getvalue(inputCPS & ".inBulgeMaking") ShadowRigMaking =getvalue(inputCPS & ".inShadowRigMaking") 'デフォーマーの数よりハンドルの数が多いと失敗するのでエラーを返す if deformerNum < handleNum then logmessage "ハンドルの数はデフォーマー数より少なくしてください",2 out = true end if 'デフォーマー数が多すぎると落ちる可能性があるので警告を出す if deformerNum > 100 then if MsgBox ("デフォーマーの数が多すぎると生成・削除に時間が掛かります。また、XSIがフリーズする可能性があります。" + vbCrLf + "OKを押すと続行します",1,"警告") = 2 then out = true end if deleteObj inputCPS inputValue = out end function '--------------------------------------------------------------------------------------------------------------------------------- '階層整理・グループ作成 '--------------------------------------------------------------------------------------------------------------------------------- sub ParentInOrder dim str DeselectAll CreateModel ,"Snake_Spine",,ModelNull str = join(CtrlNull,",") & "," str = str & join(upVBonePin,",") & "," str = str & join(handleGrobalRot,",") & "," str = str & upVBone(0) & "," str = str & bodyPath & "," str = str & bodyCrv & "," str = str & rootCns ParentObj grobalSRT, str ParentObj bodyCrv,upVBonePin DeselectAll CopyPaste CreateGroup("hideObj",HideGroupList), , ModelNull, 1 ToggleVisibility DeselectAll CopyPaste CreateGroup("controlObj",CtrlGroupList), , ModelNull, 1 DeselectAll CopyPaste CreateGroup("Envelope",EnvelopeGroupList), , ModelNull, 1 ParentObj ModelNull,grobalSRT if ShadowRigMaking then ParentObj ModelNull,ShadowRigSRT DeselectAll end sub '--------------------------------------------------------------------------------------------------------------------------------- 'body_path生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeBodyPath if makeFromCrv then set bodyPath = GetValue(Duplicate(selectedCrv)) setvalue bodyPath & ".name" , "snake_body_path" ctrlNum = bodyPath.obj.nb0d GetCurveLength bodyPath , defaultLength else set bodyPath = makeCrv("snake_body_path",ctrlNum , defaultLength) 'パス生成 end if 'カスタムパラメーター作成・スクリプトオペレーター設定 AddProp "Custom_parameter_list", bodyPath , , "status",bodyPath_CPS SIAddCustomParameter bodyPath_CPS, "Length", siDouble, 0, 0, 10000, , 5 'スクリプトオペレーター設定 dim str 'function getCrvLength_Update(ctx,out,Incrvlist) 'Out.Value = Incrvlist.Value.Geometry.curves(0).length 'end function str = "function getCrvLength_Update(ctx,out,Incrvlist)" + vbCrLf _ + "Out.Value = Incrvlist.Value.Geometry.curves(0).length" + vbCrLf _ + "end function" 'logmessage str AddScriptedOp bodyPath_CPS + ".Length",str,bodyPath + ".crvlist","getCrvLength","VBScript" end sub '--------------------------------------------------------------------------------------------------------------------------------- 'path_Ctrl生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeCtrlNull CtrlNull = makeClsNull ( "Snake_Path_Ctrl",bodyPath) changeIcon CtrlNull,4,IconSize'アイコン変更 CtrlGroupList = CtrlGroupList & join(CtrlNull,",") & "," for each i in ctrlNull dim tmp1 tmp1 = i.AddProperty( "Custom_parameter_list",,"MarkingSet") AddProxyParam tmp1,i + ".kine.local.pos" next end sub '--------------------------------------------------------------------------------------------------------------------------------- 'body_crv生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeBodyCrv set bodyCrv = makeCrv("snake_body_crv",100,1)'bodycrv生成 ApplyOp "CrvDeform", bodyCrv + ";" + bodyPath, 3, siPersistentOperation, , 0'body_pathにカーブでフォーム end sub '--------------------------------------------------------------------------------------------------------------------------------- 'ボーンのピン生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeUpVBonePin upVBonePin = makeCrvCnsNull("snake_upV_bone_pin",deformerNum+1, bodyCrv) changeIcon upVBonePin,1,0.1 HideGroupList = HideGroupList & join(upVBonePin,",") & "," end sub '--------------------------------------------------------------------------------------------------------------------------------- 'アップベクター用のボーン生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeUpVBone redim upVBone(deformerNum+1) redim vertebraUpV(deformerNum-1) set upVBone(0) = Create2DSkeleton(0,0,0,0, 1, 0, 0,90,0, 4, upVBone(2), upVBone(1))'配列0番にルート、1番にエフェクタ、以降にボーンを格納 upVBone(0).Name= "snake_upV_bone_root" upVBone(1).Name = "snake_upV_bone_eff" upVBone(2).Name = "snake_upV_bone1" SetValue upVBone(2) & ".joint.chntype", 2 for i=2 to deformerNum+1 if i > 2 then set upVBone(i) = AppendBone(upVBone(1),0,i,0) upVBone(i).Name = "snake_upV_bone" + "1" end if upVBone(i).joint.chntype = 2 next upVBone(0).root.primary_icon = 0 upVBone(0).root.shadow_icon = 7 upVBone(0).root.shadow_scaleX = iconSize*0.3 upVBone(0).root.shadow_scaleZ =iconSize*0.3 upVBone(0).root.radius = iconSize*5 'ルートのコンストレイント・ON/OFFスイッチはDisplayInfoに-- set rootCns = getprim("NULL","snake_root_cns") ApplyCns "Path",rootCns + "",bodyCrv + "" SetValue rootCns + ".kine.pathcns.lockcnsed", True ApplyCns "Direction", rootCns + "",upVBonePin(1) + "" AddExpr rootCns + ".kine.local.rotx" AddExpr rootCns + ".kine.local.roty" AddExpr rootCns + ".kine.local.rotz" AddProp "Custom_parameter_list",upVBone(0), , "DisplayInfo",root_CPS SIAddCustomParameter root_CPS, "cnsSwitch", siBool, true ApplyCns "Orientation",upVBone(0)+" " , rootCns + " " AddExpr upVBone(0) + ".kine.oricns.active",root_CPS + ".cnsSwitch" 'ルートにカスタムパラメーター作成 SIAddCustomParameter root_CPS, "Length", siDouble, defaultLength, 0.01, 10000, , 5,0,100 if onPathMode = true then SIAddCustomParameter root_CPS, "Position", siDouble, 0, 0, 1, , 5 else SIAddCustomParameter root_CPS, "Position", siDouble, 0, -10000, 10000, , 5,-100,100 end if 'ルートのカスタムパラメーターにbodycrvのカーブデフォームのプロパティをエクスプレッション dim str if stretchMode=true then CopyPaste bodyPath_CPS + ".length", ,root_CPS + ".Length" , 1 CopyPaste root_CPS + ".Length", , bodyCrv + ".crvlist.crvdeform.sclcurve", 1 if onPathMode = true then str = "(" + bodyPath_CPS + ".length" + " * " + root_CPS + ".position" +")" + " - " _ + "(" + root_CPS + ".Position" + " * " + root_CPS + ".Length" + ")" '(snake_body_path.status.length * snake_upV_bone_root.DisplayInfo.position) ' - (snake_upV_bone_root.DisplayInfo.Position * snake_upV_bone_root.DisplayInfo.Length) 'logmessage str else str = root_CPS + ".Position" end if SetExpr bodyCrv + ".crvlist.crvdeform.poscurve", str CtrlGroupList = CtrlGroupList & upVBone(0) & "," for i = 1 to Ubound(upVbone) HideGroupList = HideGroupList & upVBone(i) & "," next HideGroupList = HideGroupList & rootCns & "," 'マーキングセット登録 dim tmp1 tmp1 = upVBone(0).AddProperty( "Custom_parameter_list",,"MarkingSet") AddProxyParam tmp1,upVBone(0) + ".kine.local.ori.euler" AddProxyParam upVBone(0) + ".MarkingSet" ,root_CPS + ".position" AddProxyParam upVBone(0) + ".MarkingSet" ,root_CPS + ".length" end sub '--------------------------------------------------------------------------------------------------------------------------------- 'upVBoneをpinにストレッチ&コンストレイントさせる '--------------------------------------------------------------------------------------------------------------------------------- sub setBoneStretchCns dim tmp1,tmp2 'ApplyCnsに変数を渡すと中身書き換えられるので文字列で渡す ApplyCns "Position", upVBone(0)+"", upVBonePin(0)+""'ルートを拘束 ApplyCns "Position", upVBone(1)+"",upVBonePin(deformerNum)+"" 'エフェクタを拘束 'ボーンを拘束&ストレッチ for i=1 to deformerNum if not(i=1) then ApplyCns "Position", upVBone(i+1)+"", upVBonePin(i-1)+"" AddExpr upVBone(i+1) + ".bone.length","ctr_dist("+upVBonePin(i-1)+". , " + upVBonePin(i) + ".)" next end sub '--------------------------------------------------------------------------------------------------------------------------------- 'Vertebra生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeSnakeVertebra Vertebra = makeCrvCnsNull("snake_Vertebra",deformerNum, bodyCrv) redim Vertebra_CPS(deformerNum-1) dim str1,str2 for i=0 to Ubound(Vertebra) parentObj upVBone(i+2),Vertebra(i) str1 = str1 & Vertebra(i) + ".kine.pathcns.tangent," str2 = str2 & Vertebra(i) + ".kine.pathcns.lockcnsed," next setvalue str1,true setvalue str2,true changeIcon Vertebra,4,getvalue(upVBone(2)+".bone.length") EnvelopeGroupList = join(Vertebra,",") & "," if ShadowRigMaking or BulgeMaking then HideGroupList = HideGroupList & join(Vertebra,",") & "," end if end sub '--------------------------------------------------------------------------------------------------------------------------------- 'ハンドル生成・upVectorBaseにエクスプレッション '--------------------------------------------------------------------------------------------------------------------------------- sub makeUpVHandle handle = makeCrvCnsNull("snake_TwistHandle",handleNum,bodyCrv) '一番近いボーンの子供にする redim Vertebra_perc(deformerNum-1) redim parentNo(handleNum-1)'ハンドルの親になるボーンの配列番号 for j = 0 to deformerNum-1 Vertebra_perc(j)=getvalue(Vertebra(j) + ".kine.pathcns.perc") next for i = 0 to handleNum-1 parentNo(i) = searchNearIndex( Vertebra_perc, getvalue(handle(i) + ".kine.pathcns.perc"))+2 ParentObj upVbone(parentNo(i)),handle(i) ResetTransform handle(i), siObj next 'ハンドルに一番近いbaseと探して次のハンドルに一番近いbaseまでの間でウェイトを割り振ってエクスプレッション redim handle_perc(handleNum-1) for i = 0 to handleNum-1 handle_perc(i)=getvalue(handle(i) + ".kine.pathcns.perc") next for i = 0 to handleNum-2 dim tmp1,tmp2 tmp1 = searchNearIndex( Vertebra_perc ,handle_perc(i)) tmp2 = searchNearIndex( Vertebra_perc ,handle_perc(i+1)) for j=tmp1 to tmp2 dim weight,str weight = (vertebra_perc(j)-vertebra_perc(tmp1))/(vertebra_perc(tmp2)-vertebra_perc(tmp1)) '(handle(i) .kine.local.rotx * (1-weight)) + (handle(i+1).kine.local.rotx * weight) str = "(" & handle(i) & ".kine.local.rotx * (1 - " & weight & ")) + (" & handle(i+1) & ".kine.local.rotx * " & weight & ")" 'logmessage str AddExpr vertebra(j) + ".kine.local.rotx",str next next handleGrobalRot = makeCrvCnsNull("snake_twist_global",handleNum,bodyCrv) redim handleUpV(Ubound(handleGrobalRot)) for i=0 to Ubound(handleGrobalRot) ApplyCns "Orientation",handleGrobalRot(i)+" " , handle(i) + " " AddProp "Custom_parameter_list", handleGrobalRot(i) , , "DisplayInfo",handleGrobalRot_CPS SIAddCustomParameter handleGrobalRot_CPS, "cnsSwitch", siBool, false set handleUpV(i) = getprim ("Null","snake_twist_upV" & (i+1),handleGrobalRot(i)) ResetTransform handleUpV(i), siObj handleUpV(i).Kinematics.Local.Parameters("posz").value = 1 ApplyOp "UpVectorDefiner", handle(i) + ".kine.pathcns " + ";" + handleUpV(i), siUnspecified, siPersistentOperation, , 0 SetValue handle(i) + ".kine.pathcns.upvct_active", True SetValue handle(i) + ".kine.pathcns.upx", 0 SetValue handle(i) + ".kine.pathcns.upy", 0 SetValue handle(i) + ".kine.pathcns.upz", 1 AddExpr handle(i) + ".kine.local.roty",0 AddExpr handle(i) + ".kine.local.rotz",0 AddExpr handle(i) + ".kine.pathcns.upvct_active", handleGrobalRot_CPS + ".cnsSwitch" AddExpr handle(i) + ".kine.pathcns.tangent", handleGrobalRot_CPS + ".cnsSwitch" AddExpr handleGrobalRot(i) + ".kine.oricns.active","1 - " + handleGrobalRot_CPS + ".cnsSwitch" next changeIcon_Shadow handle,3,0,0,0,0,IconSize,IconSize*1.2,false changeIcon_Shadow handleGrobalRot,3,0,0,0,IconSize*0.8,IconSize*0.8,IconSize*0.8,false CtrlGroupList = CtrlGroupList & join(handle,",") & "," CtrlGroupList = CtrlGroupList & join(handleGrobalRot,",") & "," HideGroupList = HideGroupList & join(handleUpV,",") & "," dim tmp3 for each i in handle tmp3 = i.AddProperty( "Custom_parameter_list",,"MarkingSet") AddProxyParam tmp3,i + ".kine.local.rotx" next end sub '--------------------------------------------------------------------------------------------------------------------------------- 'たわみコントローラー生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeVerticalShearCtrl set VerShear = getPrim("Null","snake_VerticalShearCtrl",bodyCrv) set P_CrvShear = getPrim("Null","snake_VerticalShearCtrl_PCrv",VerShear) ResetTransform VerBend, siObj AddProp "Custom_parameter_list", VerShear , , "DisplayInfo",VerShear_CPS SIAddCustomParameter VerShear_CPS, "Shear_pos" , siDouble, 0 ,-1 ,2 , , 5,,, "位置" SIAddCustomParameter VerShear_CPS, "Shear_amp" , siDouble, 0 ,-10,10 , , 5,-100,100, "振幅" SIAddCustomParameter VerShear_CPS, "Shear_range", siDouble, 0.15,0.01,1 , , 5,,, "範囲" AddProp "Custom_parameter_list", P_CrvShear , , "P_Crv",P_CrvShear_CPS SIAddCustomParameter P_CrvShear_CPS, "PCrv_Shear" , siDouble, 0 ,-1 ,1 , , 5,,, "プロファイルカーブ" SIAddCustomParameter P_CrvShear_CPS, "PCrv_Shear_weight" , siDouble, 0 , 0 ,1 , , 5,,,"減衰コントロールカーブ" ApplyCns "Path", VerShear+ " " , bodyCrv + " " SetValue VerShear + ".kine.pathcns.lockcnsed", True SetValue VerShear + ".kine.pathcns.tangent", True AddExpr VerShear + ".kine.pathcns.perc", VerShear_CPS+".Shear_pos" + " * 100" SaveKey P_CrvShear_CPS + ".PCrv_Shear", 0, 1, null SaveKey P_CrvShear_CPS + ".PCrv_Shear", -100, 0, null SaveKey P_CrvShear_CPS + ".PCrv_Shear", 100, 0, null SaveKey P_CrvShear_CPS + ".PCrv_Shear_weight", 0, 1, null SaveKey P_CrvShear_CPS + ".PCrv_Shear_weight", 100, 1, null for i=0 to Ubound(Vertebra) 'パス上の位置を加算する用のパラメータ。 AddProp "Custom_parameter_list", Vertebra(i) , , "DisplayInfo", Vertebra_CPS(i) SIAddCustomParameter Vertebra_CPS(i), "pos", siDouble,0 , -1, 1, , 5 SIAddCustomParameter Vertebra_CPS(i), "Shear_weight", siDouble,1 , 0, 1, , 5 AddExpr Vertebra_CPS(i)+".pos", _ "at_time(" & "((" & ((i+0.5)/deformerNum) & " - " & VerShear_CPS & ".Shear_pos" & ") * 100" & " / fr ) / " & VerShear_CPS & ".Shear_range" _ & "," & P_CrvShear_CPS & ".PCrv_Shear )" ' "at_time((( ((i+0.5)/deformerNum) - VerShear_CPS.Shear_pos) * 100 / fr) / VerShear_CPS.Shear_range , VerShear_CPS.PCrv_Shear ) AddExpr Vertebra_CPS(i)+".Shear_weight", _ "at_time(" & ((i+0.5)/deformerNum) & " * 100 " & "/ Fr " &"," & P_CrvShear_CPS & ".PCrv_Shear_weight )" SetExpr Vertebra(i) & ".kine.pathcns.perc", ((i+0.5)/deformerNum) & " * 100" & " + ( " & Vertebra_CPS(i)+".pos" & "*" & VerShear_CPS & ".Shear_amp * " & Vertebra_CPS(i) & ".Shear_weight" & ")" next changeIcon_Shadow VerShear,2,0,0,0,0,Iconsize*2,Iconsize*2,false changeIcon_Shadow P_CrvShear,2,0,0,0,0,Iconsize*1.9,Iconsize*1.9,false 'マーキングセット登録 dim tmp1 tmp1 = VerShear.AddProperty( "Custom_parameter_list",,"MarkingSet") AddProxyParam tmp1,VerShear_CPS & ".Shear_pos" AddProxyParam tmp1,VerShear_CPS & ".Shear_amp" AddProxyParam tmp1,VerShear_CPS & ".Shear_range" CtrlGroupList = CtrlGroupList & VerShear & "," end sub '--------------------------------------------------------------------------------------------------------------------------------- 'バルジコントローラー生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeBulgeCtrl set BulgeCtrl = getPrim("Null","snake_BulgeCtrl",bodyCrv) set P_CrvBulge = getPrim("Null","snake_BulgeCtrl_PCrv",BulgeCtrl) ResetTransform BulgeCtrl, siObj AddProp "Custom_parameter_list", BulgeCtrl , , "DisplayInfo",BulgeCtrl_CPS SIAddCustomParameter BulgeCtrl_CPS, "Bulge_pos" , siDouble, 0 ,-1 ,2 , , 5,,,"位置" SIAddCustomParameter BulgeCtrl_CPS, "Bulge_amp" , siDouble, 0 ,-10 ,10 , , 5,,,"振幅" SIAddCustomParameter BulgeCtrl_CPS, "Bulge_range" , siDouble, 0.15,0.01 ,1 , , 5,,,"範囲" AddProp "Custom_parameter_list", P_CrvBulge , , "P_Crv", P_CrvBulge_CPS SIAddCustomParameter P_CrvBulge_CPS, "PCrv_Bulge" , siDouble, 0 ,-1 ,1 , , 5,,,"プロファイルカーブ" SIAddCustomParameter P_CrvBulge_CPS, "PCrv_Bulge_weight" , siDouble,0,0 ,1 , , 5,,,"減衰コントロールカーブ" ApplyCns "Path", BulgeCtrl+ " " , bodyCrv + " " SetValue BulgeCtrl + ".kine.pathcns.lockcnsed", True SetValue BulgeCtrl + ".kine.pathcns.tangent", True AddExpr BulgeCtrl + ".kine.pathcns.perc", BulgeCtrl_CPS+".Bulge_pos" + " * 100" SaveKey P_CrvBulge_CPS + ".PCrv_Bulge", 0, 1, null SaveKey P_CrvBulge_CPS + ".PCrv_Bulge", -100, 0, null SaveKey P_CrvBulge_CPS + ".PCrv_Bulge", 100, 0, null SaveKey P_CrvBulge_CPS + ".PCrv_Bulge_weight", 0, 1, null SaveKey P_CrvBulge_CPS + ".PCrv_Bulge_weight", 100, 1, null redim VertebraBulge(deformerNum-1) redim VertebraBulge_CPS(deformerNum-1) for i=0 to Ubound(Vertebra) set VertebraBulge(i) = getprim("NULL","snake_Vertebra_Bulge" & (i+1),Vertebra(i)) ResetTransform VertebraBulge(i), siObj 'スケールを加算する用のパラメータ AddProp "Custom_parameter_list", VertebraBulge(i) , , "DisplayInfo", VertebraBulge_CPS(i) SIAddCustomParameter VertebraBulge_CPS(i), "scl", siDouble,0 , -1, 1, , 5 SIAddCustomParameter VertebraBulge_CPS(i), "Bulge_weight", siDouble,1 , 0, 1, , 5 next for i=0 to Ubound(Vertebra) AddExpr VertebraBulge_CPS(i) + ".scl", _ "at_time(" & "((" & ((i+0.5)/deformerNum) & " - " & BulgeCtrl_CPS & ".Bulge_pos" & ") * 100" & " / fr ) / " & BulgeCtrl_CPS & ".Bulge_range" _ & "," & P_CrvBulge_CPS & ".PCrv_Bulge )" AddExpr VertebraBulge_CPS(i) & ".Bulge_weight", _ "at_time(" & ((i+0.5)/deformerNum) & " * 100 " & "/ Fr " & "," & P_CrvBulge_CPS & ".PCrv_Bulge_weight )" AddExpr VertebraBulge(i) & ".kine.local.sclX", "1 + (" & VertebraBulge_CPS(i) & ".scl" & " * " & BulgeCtrl_CPS & ".Bulge_amp" & " * " & VertebraBulge_CPS(i) & ".Bulge_weight )" AddExpr VertebraBulge(i) & ".kine.local.sclY", "1 + (" & VertebraBulge_CPS(i) & ".scl" & " * " & BulgeCtrl_CPS & ".Bulge_amp" & " * " & VertebraBulge_CPS(i) & ".Bulge_weight )" AddExpr VertebraBulge(i) & ".kine.local.sclZ", "1 + (" & VertebraBulge_CPS(i) & ".scl" & " * " & BulgeCtrl_CPS & ".Bulge_amp" & " * " & VertebraBulge_CPS(i) & ".Bulge_weight )" next changeIcon_Shadow BulgeCtrl,4,0,0,0,0,Iconsize*4,Iconsize*4,false changeIcon_Shadow P_CrvBulge,4,0,0,0,0,Iconsize*3.9,Iconsize*3.9,false changeIcon_Shadow VertebraBulge,4,0,0,0,0,Iconsize/2,Iconsize/2,false 'マーキングセット登録 dim tmp1 tmp1 = BulgeCtrl.AddProperty( "Custom_parameter_list",,"MarkingSet") AddProxyParam tmp1,BulgeCtrl_CPS & ".Bulge_pos" AddProxyParam tmp1,BulgeCtrl_CPS & ".Bulge_amp" AddProxyParam tmp1,BulgeCtrl_CPS & ".Bulge_range" CtrlGroupList = CtrlGroupList & BulgeCtrl & "," if ShadowRigMaking then HideGroupList = HideGroupList & join(VertebraBulge,",") & "," end if EnvelopeGroupList = join(VertebraBulge,",") & "," end sub '--------------------------------------------------------------------------------------------------------------------------------- 'シャドウリグ生成 '--------------------------------------------------------------------------------------------------------------------------------- sub makeShadowRig ShadowRig = makeNulls("snake_env",deformerNum) for i=0 to Ubound(ShadowRig) if BulgeMaking then ApplyCns "Pose",ShadowRig(i)+"",VertebraBulge(i)+"" else ApplyCns "Pose",ShadowRig(i)+"",Vertebra(i)+"" end if next set ShadowRigSRT = getPrim("NULL","snake_envSRT") parentObj ShadowRigSRT, join(ShadowRig,",") EnvelopeGroupList = join(ShadowRig,",") end sub '-------------------------------------------------------------------------------------------------------------------------- '-------------------------------------------------------------------------------------------------------------------------- '-------------------------------------------------------------------------------------------------------------------------- '-------------------------------------------------------------------------------------------------------------------------- '以下、汎用関数 '--------------------------------------------------------------------------------------------------------------------------------- 'ヌルのアイコン変更 '--------------------------------------------------------------------------------------------------------------------------------- sub changeIcon(InNull,IconNo,size) '0 なし '1 ヌル '2 環 '3 矢印円 '4 ボックス '5 円 '6 矩形波 '7 ダイアモンド '8 ピラミッド '9 尖ったボックス '10 矢印 dim str if instr(typename(InNull), "Variant()") = 1 then'引数が配列の時と単体の時で分ける for Each i in InNull str = str& i & ".null.primary_icon," next SetValue str,IconNo str = " " for Each i in InNull str = str& i & ".null.size," next SetValue str,size str = " " else SetValue InNull & ".null.primary_icon", IconNo SetValue InNull & ".null.size", size end if end sub 'シャドウアイコン変更:PIcon=true でプライマリアイコン表示のまま sub changeIcon_Shadow(InNull,IconNo,posX,posY,posZ,sclX,sclY,sclZ,PIcon) dim str if instr(typename(InNull), "Variant()") = 1 then'引数が配列の時と単体の時で分ける str = " " if PIcon = false then for Each i in InNull str = str& i & ".null.primary_icon," next SetValue str, 0 end if str = " " for Each i in InNull str = str& i & ".null.shadow_offsetX," next SetValue str, posX str = " " for Each i in InNull str = str& i & ".null.shadow_offsetY," next SetValue str, posY str = " " for Each i in InNull str = str& i & ".null.shadow_offsetZ," next SetValue str, posZ str = " " for Each i in InNull str = str& i & ".null.shadow_scaleX," next SetValue str, sclX str = " " for Each i in InNull str = str& i & ".null.shadow_scaleY," next SetValue str, sclY str = " " for Each i in InNull str = str& i & ".null.shadow_scaleZ," next SetValue str, sclZ str = " " for Each i in InNull str = str& i & ".null.shadow_icon," next SetValue str, IconNo str = " " else if PIcon = false then SetValue InNull & ".null.primary_icon", 0 SetValue InNull & ".null.shadow_offsetX", posX SetValue InNull & ".null.shadow_offsetY", posY SetValue InNull & ".null.shadow_offsetZ", posZ SetValue InNull & ".null.shadow_scaleX", sclX SetValue InNull & ".null.shadow_scaleY", sclY SetValue InNull & ".null.shadow_scaleZ", sclZ SetValue InNull & ".null.shadow_icon", IconNo end if end sub '--------------------------------------------------------------------------------------------------------------------------------- 'クラスタセンターのヌル(コントローラー)生成 '戻り値:生成したヌルの配列 '--------------------------------------------------------------------------------------------------------------------------------- function makeClsNull(InName,InObj) 'カーブのポイント数取得 Dim pointNum pointNum = InObj.obj.nb0d reDim OutNulls(pointNum-1) 'ポイント数だけループ for i=0 to PointNum - 1 set getCls = CreateCluster(InObj & ".pnt[" & i & "]" ) set getNull = GetPrim( "Null" , InName & i+1 ) set OutNulls(i) = getNull '戻り値の配列に入れとく 'ヌルの位置合わせのためにクラスタコンストレイント→即削除 ApplyCns "ObjectToCluster", getNull, getCls RemoveCns getNull 'クラスタセンター設定 ApplyOperator "ClusterCenter", getCls & ";" & getNull , 0 next makeClsNull = OutNulls end function '--------------------------------------------------------------------------------------------------------------------------------- '引数の名前、長さ、ポイント数のカーブを作成 '戻り値:作成したカーブ '--------------------------------------------------------------------------------------------------------------------------------- function makeCrv(Name,InPointNum,InLength) dim pointPos pointPos=0 set out_crv = SICreateCurve( Name, 3, 0) for i=0 to InPointNum - 1 SIAddPointOnCurveAtEnd out_crv, 0, i, 0, False, 0 next Scale out_crv , 1, 1/(InPointNum-1)*InLength, 1, siRelative, siParent, siObj, siXYZ, , , , , , , , 0 ResetTransform out_crv, siCtr, siScl, siXYZ FreezeObj out_crv set makeCrv = out_crv end function '--------------------------------------------------------------------------------------------------------------------------------- '複数の塗るを生成 '引数:名前(生成するときは名前+番号),生成する数 '戻り値:生成されたヌルを配列で '生成されるヌルには1番から番号が振られる '--------------------------------------------------------------------------------------------------------------------------------- function makeNulls(name,makeNum) redim out(makeNum - 1)'戻り値用の配列 for i=0 to makeNum - 1 set out(i) = getprim("Null",name & (i+1)) next makeNulls = out end function '--------------------------------------------------------------------------------------------------------------------------------- 'カーブにコンストレイントされた複数の塗るを生成する '引数:名前,ヌルの数,コンストレイントさせるカーブ '戻り値:生成したヌルを返す '--------------------------------------------------------------------------------------------------------------------------------- function makeCrvCnsNull(name,num,crv) dim out,tmp out = makeNulls(name,num)'ボーンのピン tmp = out 'ApplyCnsに引数として渡すと中身書き換えられるので直で変数渡しちゃだめ ApplyCns "Path", tmp , crv + " "'ピンをカーブに拘束 for i=0 to num - 1 SetValue out(i) + ".kine.pathcns.perc", i / (num-1) * 100 SetValue out(i) + ".kine.pathcns.lockcnsed", True next makeCrvCnsNull = out end function '--------------------------------------------------------------------------------------------------------------------------------- '一番近い数値が格納された配列の番号を返す '引数 数値が入った配列,探したい数値 '戻り値 配列の番号 '--------------------------------------------------------------------------------------------------------------------------------- function searchNearIndex(InArray,InNo) dim out out=0 for i=0 to UBound(InArray)-1 dim tmp1 , tmp2 tmp1 = InNo - InArray(i) tmp2 = InNo - InArray(i+1) if abs(tmp1) > abs(tmp2) then out = i+ 1 next searchNearIndex = out end function