我想以编程方式在 Blender 中创建一个 3D 模型,例如:
createcube(loc,axis)
我该怎么做呢?
(使用 Python?,如何?)
(我想用它来创建 3D 分形)
是的。Python 是 Blender 的内置语言。你可以在 Blender UI 上做的所有事情都可以在 python 代码中完成。
这是一些创建网格的示例代码:
#----------------------------------------------------------
# File meshes.py
#----------------------------------------------------------
import bpy
def createMesh(name, origin, verts, edges, faces):
# Create mesh and object
me = bpy.data.meshes.new(name+'Mesh')
ob = bpy.data.objects.new(name, me)
ob.location = origin
ob.show_name = True
# Link object to scene
bpy.context.scene.objects.link(ob)
# Create mesh from given verts, edges, faces. Either edges or
# faces should be [], or you ask for problems
me.from_pydata(verts, edges, faces)
# Update mesh with new data
me.update(calc_edges=True)
return ob
def run(origin):
(x,y,z) = (0.707107, 0.258819, 0.965926)
verts1 = ((x,x,-1), (x,-x,-1), (-x,-x,-1), (-x,x,-1), (0,0,1))
faces1 = ((1,0,4), (4,2,1), (4,3,2), (4,0,3), (0,1,2,3))
ob1 = createMesh('Solid', origin, verts1, [], faces1)
verts2 = ((x,x,0), (y,-z,0), (-z,y,0))
edges2 = ((1,0), (1,2), (2,0))
ob2 = createMesh('Edgy', origin, verts2, edges2, [])
# Move second object out of the way
ob1.select = False
ob2.select = True
bpy.ops.transform.translate(value=(0,2,0))
return
if __name__ == "__main__":
run((0,0,0))
从这里复制: https ://archive.blender.org/wiki/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Meshes/
转到此链接,看看您是否找到要解决的问题。