ActionSource または ActionSource では、パラメータへのパスを 相対名として格納します。相対名は、Parameter、または Parameter(Model または Model 名なし)の、SIObject.FullName または SIObject::GetFullName で構成されます。たとえば、Cricket というモデルの下にある立方体の posx パラメータのフル ネームは、Cricket.cube.kine.global.posx になります。 相対名を使用すると、異なるモデル間でアクション ソースの共有が簡単になります。cube.kine.global.posx のようにパラメータの相対名はどの場所でも同じだからです。
次の例は、指定した Parameter オブジェクトを使ってその相対名を戻す JScript 関数です。GetRelativePathForTarget は、指定したパラメータの FullName からモデル名を検索して取り去るために正規表現を使用します。
function GetRelativeNameForTarget( in_param )
{
var mdlname = in_param.Model.FullName;
if ( mdlname == "Scene_Root" ) {
return in_param.FullName;
} else {
var tmp = in_param.FullName;
var re = new RegExp( mdlname + ".", "i" );
return tmp.replace( re, "" );
}
}
次の例は、上の JScript コードを Python で記述した場合の関数です。 この場合の GetRelativePathForTarget も同じく、指定したパラメータの FullName からモデル名を削除するために正規表現を使用します。
def GetRelativeNameForTarget( in_param ) : import string as s mdlname = in_param.Model.FullName if mdlname == "Scene_Root" : return in_param.FullName else : return s.replace( in_param.FullName, mdlname + ".", "" )
次の例は、C++ API の場合のよく似た関数です。 ただし、C++ には文字列操作で正規表現を使用できる機能がないので、その解決策として代わりに C++ API の CString::IsEqualNoCase 関数を使用して同じ内容を実現します。
CString GetRelativeNameForTarget( Parameter& in_param )
{
Model mdl = in_param.GetModel();
CString mdlname = mdl.GetFullName();
if ( mdlname.IsEqualNoCase(L"Scene_Root") ) {
// We don't care about an object under the scene root
// (it automatically uses relative names anyways)
return in_param.GetFullName();
} else {
CString tmp = in_param.GetFullName();
CString lookfor = mdlname + L".";
CString foundsofar = L"";
CString relpath = L"";
// This loop looks to find the modelname in the full path.
// When it finds it, it collects the rest of the string
// as the relative name
for ( ULONG i=0; i<tmp.Length(); ++i ) {
if ( foundsofar.IsEqualNoCase(lookfor) ) {
relpath += tmp[i];
} else {
foundsofar += tmp[i];
}
}
// Return the relative name extracted from the full path
return relpath;
}
}