4

かなりの作業を経て、Pythonで次のコードを開発し、ベクトル[この場合は(2,2,2)]をプロットして、原点から期待する方法を指すようにしました。ロール、ピッチ、ヨーの3つの回転パラメーターの意味を理解するのに少し時間がかかりました。オイラーXYZを設定する必要があるかもしれません。

私は長く細いシリンダーをベクトルとして使用しました。これは私の目的に適しており、ブレンダーの薄い経験に適合しています。このコードは、途中に矢印(円錐)が付いたベクトルをプロットし、私の目的に非常によく適合しますが、やや厄介です。私はほとんどのベクトルで機能しますが、x<0およびy>0およびz>0の場合は失敗します

import bpy
import math
from math import *
x=-5  
y=-10
z=12
yParameter=-1.0
if y < 0:
    if x < 0: 
        yParameter = 1.0
#print ("y para is ",yParameter
for i in range (0,1):

    length=sqrt(z*z+y*y+x*x)


#Create a vector at correct orientation at the origin
bpy.ops.mesh.primitive_cylinder_add(vertices=16, radius=0.04, depth=length, end_fill_type='NGON', view_align=False, enter_editmode=False, location=(0,0,0),rotation=(-acos(z/sqrt(x*x+y*y+z*z)),0,yParameter*acos(y/sqrt(x*x+y*y))))
bpy.ops.transform.translate(value=(x/2, y/2, z/2))

bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=0.1, radius2=0, depth=0.4, end_fill_type='NGON', view_align=False, enter_editmode=False, location=(0,0,0), rotation=(-acos(z/sqrt(x*x+y*y+z*z)),0,yParameter*acos(y/sqrt(x*x+y*y))))

bpy.ops.transform.translate(value =(x / 2、y / 2、z / 2))

ベクトルと行列操作の巨大なAPIによってこの作業が簡単になると確信していますが、この自己開発のデカルト座標以外の方法を見つけるのに苦労しています。

理解しやすいコードスニペット、またはブレンダーpython内で(数学的な意味で)ベクトルを操作する方法に関するチュートリアルを教えてもらえますか?

Blender APIはパラメーターの名前とそのコーディング方法についてはかなり明確ですが、パラメーターが実際に何を意味するのかについてはほとんど、またはまったくわかりません。

4

1 に答える 1

2

これにより、一方の端が(0,0,0)で、もう一方の端が(x、y、z)の円柱が作成されます。

def createVectorLikeThing(x,y,z):
    v = Vector((x,y,z))
    up = Vector((0,0,1))
    if v!=-up:
        rot = up.rotation_difference(v)
    else:
        rot = Quaternion((1,0,0),pi)
    bpy.ops.mesh.primitive_cylinder_add(vertices=16, radius=0.01, depth=v.length, end_fill_type='NGON', view_align=False, enter_editmode=True)
    bpy.ops.transform.translate(value=(0,0,v.length/2))
    bpy.ops.object.editmode_toggle()
    bpy.ops.transform.rotate(value=(rot.angle,), axis=rot.axis)

コードはblender2.63で動作しますが、2.65では動作しません。

2.65の場合、最後の行を次のように変更します。

    bpy.ops.transform.rotate(value=rot.angle, axis=rot.axis)
于 2013-02-14T21:56:22.430 に答える