<< ■マテリアル情報を取得する 戻る ■新規マテリアルの追加 >>

■カラーを変更する

平面に割り当てたマテリアルをmetasequoia python scriptで変更する。
当初colorを出力するのに、
MQSystem.println(str(doc.material[0].color))
と記述すると
[0.220, 0.420, 0.620]
とリストで出てくるので、color[0],color[1],color[2]とできると思い込んでいました。
Inappropriate argument type.やAttributeエラーが出てしまい困りました。
ヘルプを参照したら、colorは、red,green,blueではありませんか。

MQSystem.println(str(doc.material[0].color.green))
doc.material[0].color.red=0.22
doc.material[0].color.green=0.42
doc.material[0].color.blue=0.62

と表記すれば、カラー変更が可能になりました。

最初に平面を作成し、mat1を作成し、平面に割り当てておき、以下のスクリプトを実行すると、カラー等が変更されます。

doc = MQSystem.getDocument()
num = doc.numMaterial
for x in range(0,num):
mat = doc.material[x]
if mat is None: continue
MQSystem.println(mat.name)
MQSystem.println(" color : " + str(mat.color))
MQSystem.println(" dif : %(#).3f" % {"#":mat.diffuse})
MQSystem.println(" amb : %(#).3f" % {"#":mat.ambient})
MQSystem.println(" emi : %(#).3f" % {"#":mat.emissive})
MQSystem.println(" spc : %(#).3f" % {"#":mat.specular})
MQSystem.println(" pow : %(#).3f" % {"#":mat.power})
if mat.mapType == 0:
MQSystem.println(" mapping : 0 (UV)")
elif mat.mapType == 1:
MQSystem.println(" mapping : 1 (flat)")
elif mat.mapType == 2:
MQSystem.println(" mapping : 2 (cyrindical)")
elif mat.mapType == 3:
MQSystem.println(" mapping : 3 (spherical)")
if mat.mapType != 0:
MQSystem.println(" map-scaling : " + str(mat.mapScaling))
MQSystem.println(" map-angle : " + str(mat.mapAngle))
MQSystem.println(" map-position : " + str(mat.mapPosition))
MQSystem.println(" vertex-color : %(#)d" % {"#":mat.vertexColor})
MQSystem.println(" shader : %(#)d (" % {"#":mat.shader} + mat.shaderName + ")")
if mat.textureMap != "":
MQSystem.println(" texture-map : " + mat.textureMap)
path = mat.getTextureMapPath()
if not (path is None):
MQSystem.println(" texture-map-path : " + path)
if mat.alphaMap != "":
MQSystem.println(" alpha-map : " + mat.alphaMap)
path = mat.getAlphaMapPath()
if not (path is None):
MQSystem.println(" alpha-map-path : " + path)
if mat.bumpMap != "":
MQSystem.println(" bump-map : " + mat.bumpMap)
path = mat.getBumpMapPath()
if not (path is None):
MQSystem.println(" bump-map-path : " + path)

MQSystem.println(str(doc.material[0].color))
doc.material[0].diffuse=0.2
doc.material[0].ambient=1.0
doc.material[0].emissive=0.5
doc.material[0].specular=0.2
MQSystem.println(str(doc.material[0].color.green))
doc.material[0].color.red=0.22
doc.material[0].color.green=0.42
doc.material[0].color.blue=0.62


mat2=MQSystem.newMaterial()
mat2.name="mat_test"
doc.addMaterial(mat2)
num = doc.numMaterial
MQSystem.println(str(num))

mat1.jpg
そのほか、拡散光や反射など設定を変更することもできます。いろいろと数値を変更して実験してみましょう。

出力結果例:
mat1
color : [0.620, 0.059, 0.059]
dif : 0.800
amb : 0.580
emi : 0.000
spc : 0.000
pow : 5.000
mapping : 0 (UV)
vertex-color : 0
shader : 3 (Phong)
[0.620, 0.059, 0.059]
0.0588235296309
  • -
  • -

<< ■マテリアル情報を取得する 戻る ■新規マテリアルの追加 >>