このセクションでは、C# を使用して Softimage で作業する方法のさまざまな例を紹介します。 各クラスの詳細については、「コマンドおよびスクリプト リファレンス」のオブジェクト モデルに関するドキュメントを参照してください。
Softimage へは、次の新しいキーワードで XSIApplication オブジェクトのインスタンスを作成することで、アクセスできます。
using XSIOM; CXSIApplicationClass app = new CXSIApplicationClass();
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.
}
パラメータのリストは、便利で信頼性の高い foreach ループを使用可能な ParameterCollection で返されます。
// 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);
}