我正在尝试编写一个非常基本的导出到Blender的脚本(从原始形状)。我必须绘制各种角度和位置的圆柱体。我有偏移位置和尺寸的信息。

import bpy
import bgl
from mathutils import *
from math import *

material = bpy.data.materials.new('red')
material.diffuse_color = (1.0,0.0,0.0)


def draw_cylinder(name,material,radius,depth,location,rotation,offsetPosition,offsetAngle):

    bgl.glRotatef(*offsetAngle[:4])
    bgl.glTranslatef(*offsetPosition[:3])

    bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, location=location, rotation=rotation)

    Cylinder = bpy.context.active_object
    Cylinder.name = name
    Cylinder.active_material = material

    bgl.glTranslatef(*[i*-1 for i in offsetPosition[:3]])
    bgl.glRotatef(*[i*-1 for i in offsetAngle[:4]])

    return Cylinder

cmpt = draw_cylinder('first',material,radius=1,depth=2,location=(-1,0,0),rotation=(pi/2,0,0),offsetPosition=(10,2,7),offsetAngle=(pi/2,0,1,0))


这不会在(9,2,7)[不沿y轴旋转]处拉伸圆柱体,这在哪里我非常错误?我该如何纠正。非常感谢您的帮助。

编辑:使用Blender 2.60版(python交互式控制台3.2.2)
输出显示圆柱体,其为(-1,0,0)。我希望/需要它在(9,2,7)(位置+偏移位置)

最佳答案

在功能draw_cylinder中,您需要添加两个向量:

pos = (
    location[0]+offsetPosition[0],
    location[1]+offsetPosition[2],
    location[1]+offsetPosition[2],
)


接着

bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, location=pos, rotation=rotation)


[编辑]如果需要更复杂的操作,请查看mathutils library

关于python - 用于原始Blender导出器的Blender python脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8819325/

10-11 22:03
查看更多