如何在Blender中使用python创建无缝背景?

时间:2019-04-29 08:10:57

标签: python scripting blender

我想为我的搅拌器项目创建一个无缝的背景。这是在脚本中完成的,我想将背景添加到该脚本中。

问题在于,我不知道如何仅在边缘中拉伸平面,因此以后可以将其倾斜并使其无缝。使用GUI确实很容易,但是我不知道如何在脚本中做到这一点。

我正在尝试一些事情,但是目前我只有这段代码(显然未完成,并且做得不太好):

bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
plane2 = bpy.data.objects['Plane']

dims = plane2.dimensions
plane2.dimensions = 100, 70, 35

bpy.ops.object.editmode_toggle()

bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')

bpy.context.scene.objects[0].data.edges[0]

me = bpy.context.object.data
"""
# Get a BMesh representation
bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(me)   # fill it in from a Mesh


# Modify the BMesh, can do anything here...
for e in bm.edges:
    e.co.x += 1.0
"""
bpy.context.tool_settings.mesh_select_mode = (False, True, False)

bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"value":(0, 0, 88.1553), "constraint_axis":(False, False, True), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})

bpy.ops.object.editmode_toggle()

我希望背景看起来像这样,以防有助于更好地了解目标: https://www.youtube.com/watch?v=Ycz1wQY_7KI

1 个答案:

答案 0 :(得分:0)

由于您只需要两个面作为背景,因此我将从python列表制作网格。然后添加斜角修饰符以使后角变圆。

import bpy
from bpy_extras.object_utils import object_data_add
from mathutils import Vector

verts = [
    Vector(( 50,-35,  0)),
    Vector(( 50, 35,  0)),
    Vector((-50, 35,  0)),
    Vector((-50,-35,  0)),
    Vector((-50, 35, 35)),
    Vector(( 50, 35, 35)),
]
faces = [[2,3,0,1], [5,4,2,1]]

mesh = bpy.data.meshes.new(name="Backdrop")
mesh.from_pydata(verts, [], faces)
object_data_add(bpy.context, mesh)
backdrop = bpy.context.object
bpy.ops.object.shade_smooth()

bev_mod = backdrop.modifiers.new('bevel', 'BEVEL')
bev_mod.width = 12
bev_mod.segments = 5

mat = bpy.data.materials.new('back_mat')
if bpy.app.version[1] < 80:
    mat.diffuse_color = [1,1,1] # white
else:
    # 2.80 needs alpha value in colour
    mat.diffuse_color = [1,1,1,1]
backdrop.active_material = mat