このセクションでは、C# を使用して Softimage で作業する方法のさまざまな例を紹介します。 各クラスの詳細については、「コマンドおよびスクリプト リファレンス」のオブジェクト モデルに関するドキュメントを参照してください。
Softimage にアクセスするには、XSIApplication オブジェクトのインスタンスを、new キーワードを指定して作成します。
using XSIOM; CXSIApplicationClass app = new CXSIApplicationClass();
XSIApplication クラスに加えて、次のオブジェクトのインスタンスを作成するには、この構文を使用する必要があります。
X3DObject.AddGeometry メソッドは、新しい X3DObject:
// returns the root object
using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Model root = app.ActiveSceneRoot;
// create object as a child of the root
X3DObject obj = root.AddGeometry("Torus", "MeshSurface", "Torific");
子のコレクションのオブジェクトの正確なインターフェイスが不明な場合は、基本の X3DObject クラスを使用するか、SIObject.IsClassOf メソッドを使用してテストし、より限定的なクラスに強制変換できます。
// returns the root object
using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Model root = app.ActiveSceneRoot;
// create object as a child of the root
X3DObject obj = root.AddGeometry("Torus", "MeshSurface", "Torific");
// browse the 3d objects under the scene root
X3DObjectCollection kids = root.FindChildren("", "", "", true);
Log("Total # of kids: " + kids.Count);
foreach (X3DObject thing in kids)
{
if (thing.IsClassOf(siClassID.siCameraID))
{
Camera cam = (Camera)thing;
Log(cam.Name);
continue;
}
if (thing.IsClassOf(siClassID.siCameraRigID))
{
CameraRig camRig = (CameraRig)thing;
Log(camRig.Name);
continue;
}
if (thing.IsClassOf(siClassID.siLightID))
{
Light lite = (Light)thing;
Log(lite.Name);
continue;
}
if (thing.IsClassOf(siClassID.siLightRigID))
{
LightRig liteRig = (LightRig)thing;
Log(liteRig.Name);
continue;
}
if (thing.IsClassOf(siClassID.siModelID))
{
Model mdl = (Model)thing;
Log(mdl.Name);
continue;
}
if (thing.IsClassOf(siClassID.siNullID))
{
Null n = (Null)thing;
Log(n.Name);
continue;
}
if (thing.IsClassOf(siClassID.siX3DObjectID))
{
X3DObject obj3d = (X3DObject)thing;
Log(obj3d.Name);
continue;
}
if (thing.IsClassOf(siClassID.siParameterID))
{
Parameter param = (Parameter)thing;
Log(param.Name);
continue;
}
// etc.
}
Parameter リストは ParameterCollection で返されます。これを使用すると、便利で信頼性の高い foreach ループを使用できます。
// returns the root object
using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Model root = app.ActiveSceneRoot;
// create object as a child of the root
X3DObject obj = root.AddGeometry("Torus", "MeshSurface", "Torific");
// find the parameters under the torus
ParameterCollection paramlist = obj.Parameters;
Log("Total # of parameters found: " + paramlist.Count);
foreach (Parameter param in paramlist)
{
Log(param.Name + " is a " + param.ValueType);
}