문제

I want to create a 3D model in Blender programmatically Something like:

createcube(loc,axis)

How do I do this?
(Using Python?, How? )
(I want to use this to create 3D fractals)

도움이 되었습니까?

해결책

Yes. Python is a built-in language for Blender. Everything you can do on the Blender UI can be done in python code.

This is some example code to create meshes:

#----------------------------------------------------------
# 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))

Copied from here: https://archive.blender.org/wiki/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Meshes/

Go to this link and see if you find what you are looking to solve.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top