Extensible Application Markup Language (XAML) は、 Windows Presentation Foundation (WPF)アプリケーションの開発に使用されます。
XAML ファイルは、3ds Max 2010 以降のリボンおよびアプリケーション メニューの内容の定義に使用されます。
3ds Max 2010 では、既存の機能を変更したり新しい機能を追加したりしなければなりません。
3ds Max 2011 から、専用のツールを使用してリボン インタフェースの XAML ファイルをカスタマイズできるようになりました。
XAML コードに複数の MAXScript コントロールを追加して、MacroScript、スピナー、カラー ピッカーなどの機能を統合することもできます。
理論上は ActionItem を定義する MacroScript は、以下の構文を使用してアプリケーション メニューに追加することができます。
{wpfmax:ActionItem MacroCategory=<Category>, MacroName=<MacroScriptName> }
例:
たとえば、アプリケーション メニューの[書き出し] (Export)サブメニューに、サードパーティ製の BFF ファイル形式でシーンを書き出すための新しいオプションを追加するには、\ui\ApplicationMenu.xaml ファイルの、次のようなヘッダから始まる定義の内部に、以下の記述を追加します。
<ApplicationMenuItem Text="Export" IsSplit="true" Id="ExportSplit" ...
<ApplicationMenuItem Text="Bobo's File Format" Id="BFFExp" KeyTip="B" LargeImage="Icons/ApplicationMenu/export_32.ico" Description="Exports the scene in the MAXScript-based BFF format." CommandHandler="{wpfmax:ActionItem MacroCategory=Bobo_s Tools, MacroName=BFF_Exporter}"/>
XAML ファイルを保存しなおして 3ds Max のアプリケーション メニューを開くと、次のようなコマンドが追加されています。
リボンの XAML ファイルには、浮動小数点または整数のスピナー コントロールを定義できます。スピナーは、構造体の内部に定義された 2 つのコールバック関数の定義を介してシーンとの対話を行います。
構文
<wpfmax:MaxSpinnerFloat Id=<string>ID MinWidth=<string>MinWidth Width=<string>Width Height=<string>Height Min=<string>MinValur Max=<string>MaxValue Scale=<string>ScaleValue init=<string>InitValue ToolTip=<string>Tooltip MaxscriptCallback=<string>ColorSwatchCallbackStruct />
<wpfmax:MaxSpinnerInt Id=<string>ID MinWidth=<string>MinWidth Width=<string>Width Height=<string>Height Min=<string>MinValue Max=<string>MaxValue Scale=<string>ScaleValue init=<string>InitValue ToolTip=<string>Tooltip MaxscriptCallback=<string>ColorSwatchCallbackStruct />
例:
以下は、球やティーポットのようなオブジェクトの半径を変更する浮動小数点スピナーを定義する場合の例です。
XAML コード:
<wpfmax:MaxSpinnerFloat Id="FloatSpinnerSample" MinWidth="40" Width="40" Height="16" min="0.0" max="10000.0" scale="1.0" init="1.0" MaxscriptCallback="MySpinnerFloat"/>
MAXSCRIPT コード:
--Define a global struct with two functions - OnChange() and GetValue() --These will be called by the Ribbon spinner thanks to the --MaxscriptCallback definition: struct MySpinnerFloat ( fn OnChanged Value = ( for o in selection where is Property o #radius do o.radius = Value ), fn GetValue = ( if selection.count > 0 then for o in selection where is Property o #radius do return o.radius else 0 ) ) --The OnChanged() function will be called when the value in the UI is changing. --The GetValue() function will be called when the system needs to update the value in the UI.
リボンの XAML ファイルには、ColorPicker UI コントロールを定義することができます。カラー ピッカーは、構造体の内部に定義された 2 つのコールバック関数の定義を介してシーンと対話します。
構文
<wpfmax:MaxRibbonColorSwatch Id="ID" MinWidth=<string>MinWidth Width=<string>Width Height=<string>Height MaxscriptCallback=<string>ColorSwatchCallbackStruct />
リボンの XAML ファイルには、MAXScript コマンドの呼び出しを定義することができます。このコマンドには、任意の有効な MAXScript 式を使用できます。
構文
<wpfmax:MaxscriptCommand Maxscript=<string>Expression MaxscriptToggleOff=<string>OffExpression />
例:
リボンの[縁取り]サブオブジェクト ボタンの実際のコードを以下に示します。
このボタンのトグルがオンの場合は、MAXScript コマンド "subObjectLevel = 3" を呼び出して[縁取り]モードを設定します。
このボタンのトグルがオフの場合は、MAXScriptToggleOff 式、"subObjectLevel = 0" が呼び出されます。
コードのその他の部分では、トグルがオンまたはオフの場合に可視にすべきパネルを定義しています。
XAML コード:
<wpfmax:MaxSubjectobjectToggleButton Id="mBordermode" Text="Border" Mode="Border" Orientation="Vertical" ShowText="False" Size="Standard" Image="Icons/Modeling/bordermode_editpolygons.ico" > <wpfmax:MaxSubjectobjectToggleButton.CommandHandler> <wpfmax:MaxscriptCommand Maxscript="subobjectLevel = 3" MaxscriptToggleOff="subobjectLevel = 0" /> </wpfmax:MaxSubjectobjectToggleButton.CommandHandler> <s:String>AUseSS, EModifyPanel, ESelectPanel, ESelectLoopsPanel, ESelectByPanel, AStorePanel, ANamedSetsPanel, APatternsPanel</s:String> <s:String>BBorderEdgesPanel, ETriangulationPanel, VGeometryPanel, VCutsPanel, VAlignPanel, VSubdivisionPanel, VPaintDeformPanel, OPropertiesPanel</s:String> </wpfmax:MaxSubjectobjectToggleButton>