Blender Control 〜Pythonでオブジェクトを変形する〜
前回は、基本をおさらいしました。
そして、作成した(プリミティブ)オブジェクトを移動するスクリプトを作成しました。
というか叩きました。。。
今回は、変形させてみようと思います。
いつも通りの画面構成を開きます。以下のように「Scripting」を選択します。
下のコードは、自分が叩いてみたコードです。
>>> ob = bpy.context.object # 画面上のオブジェクト(1つだけなのでこれで良い)
※複数ある場合は、bpy.context.object['オブジェクト名']とする
>>> ob.scale = (3,3,3) # オブジェクトを変形
>>> ob.scale = (3,3,2)
>>> ob.scale = (3,1,2)
>>> ob.scale = (1,1,2)
>>> ob.scale = (1,1,2)
>>> ob.location = (0,0,0) # オブジェクトを移動
>>> ob.location = (0,0,1)
>>> ob.location = (0,0,1.5)
>>> ob.location = (0,0,2)
>>> ob.location = (0,0,0)
>>> ob.scale = (1,1,1)
とりあえず、オブジェクトの大きさを変更し、移動させたものです。
そして、オブジェクトの3次元の座標を取得する
>> bpy.context.object.matrix_local.to_3x3()
Matrix(((1.0, 0.0, 0.0),
(0.0, 1.0, 0.0),
(0.0, 0.0, 1.0)))
4次元?
>> bpy.context.object.matrix_local.to_4x4()
Matrix(((1.0, 0.0, 0.0, -0.5335574150085449),
(0.0, 1.0, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0),
(0.0, 0.0, 0.0, 1.0)))
>>> bpy.context.object.matrix_local.to_translation()
Vector*1
>>> bpy.context.object.matrix_local.to_scale()
Vector*2
>>> bpy.context.object.matrix_local.to_quaternion()
Quaternion*3
>>> bpy.context.object.matrix_local.to_euler(
to_euler(order, euler_compat)
.. method:: to_euler(order, euler_compat)
Return an Euler representation of the rotation matrix
(3x3 or 4x4 matrix only).
:arg order: Optional rotation order argument in
['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].
:type order: string
:arg euler_compat: Optional euler argument the new euler will be made
compatible with (no axis flipping between them).
Useful for converting a series of matrices to animation curves.
:type euler_compat: :class:`Euler`
:return: Euler representation of the matrix.
:rtype: :class:`Euler`
うーむ、最後の奴(XYZ...)がよくわかりませんでした。調べておきます。
でわ(笑)
次回は、初めから変形させます。