Softimage において何らかの変更が発生するたびに、カスタム ディスプレイ ホストは ViewContext オブジェクトを使用して、カスタム ディスプレイに通知を出します。 この ViewContext オブジェクトは、カスタム ディスプレイが初期化されるときにも使用可能です。
以下のサンプルでは、カスタム ディスプレイによって Win32 ダイアログが作成され、ViewContext.GetParentWindowHandle の呼び出しを使用して Softimage ウィンドウの子として関連付けています。 先に述べたように、通知の時点で ViewContext オブジェクトを受け取ります。 ViewContext を使用すると、関連する通知情報を検索できます。 このクラスの詳細については、「C++ API リファレンス」の「ViewContext」を参照してください。
ViewContext クラスは、最上位レベルの Windows ハンドル(hWnd)へのアクセスを可能にする関数(GetParentWindowHandle)を含んでいます。
以下の例では、カスタム ディスプレイを初期化して、Windows ハンドルを取得しています。 この例では、ViewContext で指定された Windows ハンドルの子として、ダイアログが作成されます。
LRESULT CCustomUI::Init( XSI::CRef& in_pViewCtx )
{
XSI::ViewContext l_vViewContext = in_pViewCtx;
l_hWnd = CreateDialog( __gInstance , MAKEINTRESOURCE(IDD_CUSTOMUI_EXAMPLE), (HWND)l_vViewContext.GetParentWindowHandle(), (DLGPROC)_view_proc);
return S_OK;
}
また、通知データ(GetNotificationData)も ViewContext で取得されます。
LRESULT CCustomUI::Notify ( XSI::CRef& in_pViewCtx )
{
using namespace XSI;
// Convert the CRef into a ViewContext
XSI::ViewContext l_vViewContext = in_pViewCtx;
// Retrieve the notification information from the view context
XSI::siEventID in_eNotifcation;
void* in_pData;
l_vViewContext.GetNotificationData ( in_eNotifcation, &in_pData );次の例は、Motif でカスタム ディスプレイを正常に初期化する方法を示したものです。
void XWindowExample_Init (XSI::CRef in_pViewCtx)
{
// Get the view context object
XSI::ViewContext l_vViewContext = in_pViewCtx;
// Ask Softimage for the Top Level Widget
Widget g_TopLevel = (Widget)l_vViewContext.GetTopLevelWidget();
// Initialize our Widget from class
XtInitializeWidgetClass ( xmFormWidgetClass );
// Create a form widget and parent it to the Top Level Widget Softimage has provided
g_MyWindow = XtVaCreateManagedWidget ( "main_form",
xmFormWidgetClass,
g_TopLevel,
XmNwidth, 300,
XmNheight, 300,
NULL );
// Create a button and parent it to the form
g_theWidget = XtVaCreateManagedWidget("main_button",
xmPushButtonWidgetClass,
g_MyWindow,
XmNlabelString, XmStringCreate ("Push Me", XmSTRING_DEFAULT_CHARSET),
NULL );
// Create a second button and parent it to the form
g_theWidget2 = XtVaCreateManagedWidget("main_button2",
xmPushButtonWidgetClass,
g_MyWindow,
XmNx,100,
XmNy,100,
XmNlabelString, XmStringCreate ("Dont Push Me", XmSTRING_DEFAULT_CHARSET),
NULL );
XtSetMappedWhenManaged(g_TopLevel, 0);
// Add callback functions
XtAddEventHandler( g_theWidget, ButtonPressMask, FALSE, ButtonCB, NULL );
XtAddEventHandler( g_theWidget2, ButtonPressMask, FALSE, ButtonCB2, NULL );
XtRealizeWidget(g_TopLevel);
// This will register our form class (our shell object) with Softimage Custom Display
// Architecture. It is VERY IMPORTANT that this is done at the end of the
// initialization and after the widgets have been Realized.
//
// Internally, this will start the Xt main loop and will start broadcasting
// messages
l_vViewContext.SetXWindowTopLevel ( (void*)XtWindowOfObject(g_MyWindow) );
}
カスタム ディスプレイが初期化さると、以下の複数のクラスを使用して Softimage シーン内の変更を通知できます。
CSelectionChangeNotification: Softimage においてコンポーネント上の選択内容が変更された場合、ディスプレイ ホストによって、新しい選択リストが CRef オブジェクトの配列として返されます。
CTimeChangeNotification: Softimage においてタイムラインが変更された場合、ディスプレイ ホストによって、現在の時刻およびその状態(stop、pause、step、scrub など)が返されます。
CValueNotification: コンポーネントまたはオブジェクトの値が変更された場合、ディスプレイ ホストによって、変更された値が返されます。 何が返されるかは、オブジェクトまたはコンポーネントが何であるかによって異なります。 たとえば、シーン内のオブジェクトの位置が変更された場合は、ディスプレイ ホストによって、グローバルおよびローカル KinematicState 状態オブジェクトが 2 つの異なる通知で送信されます。ポイント、ポリゴン、または他の種類のプリミティブが値によって表される場合は、Primitive が返されます。 そのクラスで使用可能な戻り値の詳細については、「C++ API リファレンス」を参照してください。
カスタム ディスプレイ ホスト専用に定義されるクラスおよび関数の詳細については、「C++ API クラス リファレンス」を参照してください。
カスタム ディスプレイでは、Softimage に正常に接続して .dll をプラグイン レジスタに登録するために、5 つのコールバックを定義する必要があります。
プラグインが初めて初期化されるときに、Softimage によって呼び出されます。 このコールバックは必須です。
void MyPluginName_Init (XSI::CRef in_pViewCtx)
カスタム ディスプレイでは、Softimage の自己インストール プラグイン メカニズムが利用されています。 これらのコールバックの簡単な説明を以下に示します。 自己インストール プラグインの詳細については、「カスタマイズをビルドおよび配布する」を参照してください。
カスタム ディスプレイ ホストを登録し(XSILoadPlugin)、自己インストール項目として定義する(RegisterCustomView)方法を、次に示します。
XSI::CStatus XSILoadPlugin( XSI::PluginRegistrar& in_reg )
{
in_reg.PutAuthor( L"SoftimageUser" );
in_reg.PutName( L"MyPluginName" );
in_reg.PutVersion( 1, 0 );
in_reg.RegisterCustomView( L"MyPluginName" );
return XSI::CStatus::OK;