addModifier()
または modPanel.addModToSelection()
メソッドを使用して、オブジェクトのモディファイヤ スタックにモディファイヤや SpacewarpModifier の一連のクラスを作成および追加できます。特に記載しない限り、モディファイヤという用語はいずれかのクラスのメンバという意味で使用されます。
単一のモディファイヤを作成し、これをいくつかのオブジェクトに追加することによって、オブジェクト間でこのモディファイヤを共有できます。これは 3ds Max ユーザ インタフェースのオブジェクトの選択にモディファイヤを適用する場合と同様です。以下のクラスのコンストラクタは、示されている既定値を持つオプション キーワード引数として、表のいずれのプロパティでも取得できます。
既存のモディファイヤへのアクセス方法は 2 つあります。
モディファイヤはノードのプロパティとしてアクセスできます。
<node>
シーン オブジェクト上の名前、位置、長さなどのプロパティにアクセスすると、MAXScript ではオブジェクト上のモディファイヤもプロパティとして認識されます。たとえば、次のようになります。
$box001.heightsegs --get creation parameter
$box001.twist --get the twist modifier
$box001.twist.angle --the twist’s angle
このように、モディファイヤのサブプロパティとしてモディファイヤ プロパティにアクセスできます。モディファイヤ名の中に空白があるとき、パス名の場合と同様に下線「_」を空白として使用できます。次のようになります。
$box001.uvw_map --to get the ‘UVW Map’ modifier
上に述べたプロパティ アクセスは単純な状況では動作しますが、同名のモディファイヤが複数存在したり、作成パラメータと同じ名前のモディファイヤが存在する場合があります(常に後者が最初に検索される)。
この場合は、モディファイヤ配列メカニズムを使用します。これにより、いくつかの方法でインデックス付けできるモディファイヤ配列が生成されます。
b = box()
$box001.modifiers --get the array or modifiers
$box001.modifiers[3] --get the 3rd modifier counted from top of the list
$box001.modifiers[#twist] --get the modifier named "twist" using name literal
$box001.modifiers["ffd 4x4x4"] --get the FFD named "ffs 4x4x4" using string
$box001.modifiers[bend] --get the Bend by class (Added in 3ds Max 2013)
.modifiers 配列上で for ループを使用してすべての既存のモディファイヤをループし、それらの名前、クラス、プロパティを確認して必要なモディファイヤを見つけることができます。
.modifiers
配列内のモディファイヤにそのインデックスを使用してアクセスすることができます。
モディファイヤは Modifier スタックに示すように上から順にインデックス付けされ、最初が 1 となります。
インデックスが範囲外の場合、すなわち配列内のモディファイヤの数よりも多いか、1 未満の場合は undefined
の値が返されます。
FOR ループとインデックスのサンプル設定
t=teapot() --create a teapot addmodifier t (bend angle:30) --add a Bend modifier with Angle 30 addmodifier t (bend angle:60 direction:90) --add a Bend modifier with angle 60 and dir 90 addmodifier t (twist angle:180) --add a Twist modifier with Angle 180
FOR ループとインデックスのサンプル:
--The following will find all Bend modifiers with Angle less than 90 and change the Angle to 90 for m in t.modifiers where classof m == Bend and m.angle < 90 do m.angle = 90 --The following will find all modifiers (in this case both the Bends and the Twist) --with an Angle property and change it to 0 for m in t.modifiers where isProperty m #Angle do m.angle = 0 --The following will delete modifiers that have a direction property other than 0. --On our case this is the second, upper Bend modifier. --Note that we must count backwards from bottom of the stack because deleting a modifier --will renumber the modifiers array and we could otherwise miss a modifier: for m = t.modifiers.count to 1 by -1 \ where isProperty t.modifiers[m] #Direction and t.modifiers[m].direction != 0 do deleteModifier t m
.modifiers
配列内のモディファイヤに名前リテラルを使用してアクセスすることができます。
名前のスペース部分には、プロパティへのアクセスの場合のように下線「_」を使用します。
2 つのモディファイヤの名前が同じ場合は、一番上のモディファイヤが返されます。
指定された名前のモディファイヤが配列内に存在しない場合は、undefined
の値が返されます。
.modifiers
配列内のモディファイヤに名前文字列を使用してアクセスすることができます。
名前文字列のアクセスでは大文字と小文字が区別されます。
2 つのモディファイヤの名前が同じ場合は、一番上のモディファイヤが返されます。
指定された名前のモディファイヤが配列内に存在しない場合は、undefined
の値が返されます。
名前リテラルと名前文字列によるアクセスの例
t=teapot() --create a teapot addmodifier t (ffd_4x4x4()) --add a FFD 4x4x4 modifier with default name addmodifier t (ffd_2x2x2 name:"My FFD") --add a FFD 2x2x2 modifier with custom name addmodifier t (twist angle:90 name:"My Twist") --add a twist with custom name t.modifiers[#ffd_4x4x4] --try to access by name literal t.modifiers[#ffd_2x2x2] --try to access by name literal - that name does not exist! t.modifiers[#My_FFD] --try to access by the custom name - that works t.modifiers[#My_Twist] --try to access by the custom name - also works t.modifiers["ffd 4x4x4"] --same as above, but with string, so we can use spaces t.modifiers["ffd 2x2x2"] --that name does not exist, so we get undefined back t.modifiers["My FFD"] --this is the correct name, so we get it now t.modifiers["My Twist"] --this is also the correct name, so we get the Twist t.modifiers["mY tWiSt"] --the names are case-insensitive, so this returns the same Twist t.modifiers["My_Twist"] --we can even replace spaces with underscores in string names! theName = #My_Twist --in other words, if we have a name literal, t.modifiers[theName] --we can use it as name literal, t.modifiers[theName as string] --or as string and both will produce the same result!
スクリプト リスナー出力:
$Teapot:Teapot001 @ [0.000000,0.000000,0.000000] OK OK OK FFD_4x4x4:FFD 4x4x4 undefined FFD_2x2x2:My FFD Twist:My Twist FFD_4x4x4:FFD 4x4x4 undefined FFD_2x2x2:My FFD Twist:My Twist Twist:My Twist Twist:My Twist Twist:My Twist Twist:My Twist OK
3ds Max 2013 およびそれ以降では、.modifiers
配列内のモディファイヤに、その名前ではなくクラスを使用してアクセスすることができます。
2 つのモディファイヤのクラスが同じ場合は、一番上のモディファイヤが返されます。
指定されたクラスのモディファイヤが配列内に存在しない場合は、undefined
の値が返されます。
例:
t=teapot() --create a teapot addmodifier t (bend name:"MyBendAtBottom") --add a Bend modifier addmodifier t (bend name:"MyBendOnTop") --add another Bend modifier addmodifier t (twist name:"MyTwist") --add a Twist modifier t.modifiers[twist] --access the Twist t.modifiers[bend] --access the top-most Bend ("MyBendOnTop") t.modifiers[skew] --undefined, because no Skew was added
リスナー出力:
$Teapot:Teapot001 @ [0.000000,0.000000,0.000000] OK OK OK Twist:MyTwist Bend:MyBendOnTop undefined
モディファイヤと SpacewarpModifier クラスから直接派生するクラスの詳細は、「モディファイヤおよび SpacewarpModifier のタイプ」を参照してください。
モディファイヤと SpacewarpModifier クラスから直接派生するすべてのクラスに共通のプロパティ、演算子、メソッドの詳細は、「モディファイヤの共通プロパティ、演算子、メソッド」を参照してください。
モディファイヤと SpacewarpModifier クラスは MAXWrapper クラスから派生し、このクラスのプロパティとメソッドを継承します。これらのプロパティおよびメソッドについては、「MAXWrapper の共通プロパティ、演算子、メソッド」を参照してください。