Beispiel #1
0
def Map():
    bpy.ops.mesh.primitive_plane_add(2, enter_editmode=True)
    obj = bpy.context.object
    bpy.ops.object.mode_set(mode="EDIT")
    bpy.ops.mesh.subdivide(number_cuts=100)
    bpy.ops.object.mode_set(mode="OBJECT")

    Materials.NoiseMap().apply_material(obj)
Beispiel #2
0
def torus(firstCircleDiameter, secondCircleDiameter):
    mesh = bpy.data.meshes.new("torus_mesh")  # add a new mesh
    obj = bpy.data.objects.new("torus",
                               mesh)  # add a new object using the mesh

    scene = bpy.context.scene

    bpy.context.collection.objects.link(obj)
    bpy.context.view_layer.objects.active = obj  # set as the active object in the scene

    bpy.data.objects["torus"].select_set(True)

    mesh = bpy.context.object.data
    bm = bmesh.new()

    t = Torus(mathutils.Vector((0, 0, 0)), firstCircleDiameter,
              secondCircleDiameter)

    vertices = t.vertices()
    for v in vertices:
        bm.verts.new((v.x, v.y, v.z))  # add a new vert

    if hasattr(bm.verts, "ensure_lookup_table"):
        bm.verts.ensure_lookup_table()

    indices = t.triangles()
    for i in range(0, len(indices), 3):

        v1 = bm.verts[indices[i]]
        v2 = bm.verts[indices[i + 1]]
        v3 = bm.verts[indices[i + 2]]

        bm.faces.new((v1, v2, v3))

    # Recalculate normal.
    bm.normal_update()

    # make the bmesh the object's mesh
    bm.to_mesh(mesh)
    bm.free()  # always do this when finished
    values = [True] * len(mesh.polygons)
    mesh.polygons.foreach_set("use_smooth", values)

    Materials.SmoothColor((0., 0., 0., 0.)).apply_material(obj)
    bpy.data.objects['Camera'].location = [0, 0, 10]
    BlenderUtils.update_camera(bpy.data.objects['Camera'],
                               focus_point=obj.location,
                               distance=11.53)

    scene.render.resolution_x = 1920
    scene.render.resolution_y = 1920
Beispiel #3
0
def fractal_tetrahedron(iterations):
    """
    Generate the tetrahedron
    :param iterations: iterations of the tetrahedron
    """

    # Create the scene
    scene = bpy.context.scene

    scale = 4
    initial_tetrahedron = Tetrahedron(scale)

    # Create the initial tetrahedron : a big pyramid
    initial_tetrahedron.set_vertices(initial_tetrahedron.calculate_vertices())

    tetrahedrons = [initial_tetrahedron]

    # Iterations of the tetrahedron

    for i in range(0, iterations):
        tetrahedrons = generate_iteration(tetrahedrons, scale)

    # Get all vertices of every tetrahedron cells
    vertices = []
    for obj in tetrahedrons:
        obj_vertices = obj.get_vertices()
        for vert in obj_vertices:
            vertices.append(vert)

    mesh = bpy.data.meshes.new("teta_mesh")  # add a new mesh
    obj = bpy.data.objects.new("tetahedron", mesh)  # add a new object using the mesh

    bpy.context.collection.objects.link(obj)
    bpy.context.view_layer.objects.active = obj  # set as the active object in the scene

    bpy.data.objects["tetahedron"].select_set(True)

    mesh = bpy.context.object.data
    bm = bmesh.new()

    for v in vertices:
        bm.verts.new((v[0], v[1], v[2]))
    
    if hasattr(bm.verts, "ensure_lookup_table"):
        bm.verts.ensure_lookup_table()

    # Create groups of 4 tetrahedron-cell to create every triangles of the full tetrahedron
    groups = int(len(vertices) / 4)
    for i in range(0, groups):
        v0 = bm.verts[4*i]
        v1 = bm.verts[4*i+1]
        v2 = bm.verts[4*i+2]
        v3 = bm.verts[4*i+3]
        bm.faces.new((v0, v1, v2))
        bm.faces.new((v0, v1, v3))
        bm.faces.new((v1, v2, v3))
        bm.faces.new((v2, v3, v0))

    # Recalculate normal.
    bm.normal_update()

    # make the bmesh the object's mesh
    bm.to_mesh(mesh)
    bm.free()
    
    Materials.SmoothColor((0., 0., 0., 0.)).apply_material(obj)
    bpy.data.objects['Camera'].location = [0, 0, 10]
    BlenderUtils.update_camera(bpy.data.objects['Camera'],
                                     focus_point=obj.location,
                                     distance=11.53)

    scene.render.resolution_x = 1920
    scene.render.resolution_y = 1920
 def material(self):
     return Materials.SmoothColor(color=(1., 0., 0., 0.))
 def material(self):
     return Materials.HeightMapColor()
 def material(self):
     return Materials.SmoothColor((1., 1., 1., 1.))