このセクションでは、C++ API クラス ライブラリを使用して Softimage を操作するさまざまな例を紹介します。 他のコード例や各クラスの詳細については、「C++ API リファレンス」を参照してください。
次のコードは、C++ API の使い方に関するサンプルです。「C++ API リファレンス」では、豊富な例を紹介しています。
// gets the application object, which you can use to communicate with Softimage // eg., Application app; app.LogMessage( "Welcome to Softimage!" );
// returns the reference root object namespace XSI; Application app; CRef rootRef = app.GetActiveSceneRoot(); // create object with a reference object X3DObject rootObj(rootRef);
// returns the reference root object
namespace XSI;
CRef rootRef = app.GetActiveSceneRoot();
// create object with a reference object
X3DObject rootObj(rootRef);
// get children recursively
CRefArray childArray = rootObj.FindChildren(L"",L"",L"");
// count number of children
for ( long i=0; i<childArray.GetCount();i++ )
{
CRef ref = childArray[i];
if ( ref.IsA( xsi3DObjectType ) )
{
dw3DObjectCount++;
}
else if ( ref.IsA( xsiModelType ) )
{
dwModelCount++;
}
else if ( ref.IsA( xsiChainElementType ) )
{
dwChainElementCount++;
}
else if (ref.IsA( xsiDirectedObjectType ) )
{
dwDirectedObjectCount++;
}
else if (ref.IsA( xsiNullType ) )
{
dwNullCount++;
}
else if (ref.IsA( xsiParticleCloudType ) )
{
dwParticleCloudCount++;
}
else
{
dwUnknownCount++;
}
}
using namespace XSI;
Application app;
CRefArray array;
GetSomeObjects(array,app);
// Find all X3DObjects in the scene and add them to the ref array
CStringArray emptyArray;
Model root( app.GetActiveSceneRoot() );
array += root.FindChildren( L"", L"", emptyArray, true );
// add grid's parameters to ref array
X3DObject grid;
root.AddGeometry( L"Grid", L"MeshSurface", L"", grid );
array += grid.GetParameters();
for (long i = 0; i < array.GetCount(); ++i )
{
app.LogMessage(L"");
CRef ref(array[i]);
app.LogMessage( L">>Reference object class type: " + ref.GetClassName() );
if ( ref.IsA( siSIObjectID ) )
{
SIObject siobj(ref);
app.LogMessage( L"\tObject name: " + siobj.GetName() );
}
if ( ref.IsA( siX3DObjectID ) )
{
X3DObject xobj(ref);
app.LogMessage( L"\tNumber of children : "
+ CValue(xobj.GetChildren().GetCount()).GetAsText() );
}
if ( ref.IsA( siParameterID ) )
{
Parameter param(ref);
app.LogMessage( L"\tParameter's value: " + param.GetValue().GetAsText() );
}
}