ActionSource または ActionSource は、パラメータへのパスを相対名で保存します。 相対名は、SIObject.FullName または SIObject::GetFullName、Parameter または Parameter(Model または Model の名前なし)。 たとえば、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; } }