bottle

Übersicht: Python & Blender


Objectives

a From a simple basic form to a more complex object. Let's create a bottle, step by step.

Instructions

Tasks:
  1. Change the shape of the bottle.
  2. Add a bottle cap or a cork.
  3. Add a transparent color.

Modeling from a basic shape

A round object such as a bottle is an ideal form to extrude an basic shape and calculate an 3D object.

/use-cases/art/bottle/bottle.png

Let's start with the bottom.

/use-cases/art/bottle/bottle-bottom.png

Extrude a circle from bottom to the top with altered diameter.

/use-cases/art/bottle/bottle2.png

For thickness extrude from top to bottom a circle and shrink its size.

The script

use-cases/art/bottle/bottle-en.py (Source)

#! bpy
"""
Name: 'Python und Blender'
Blender: 2.7x
Group: 'Use-Case'
Tooltip: 'Create a body with extrude'
"""

import bpy


def bottle():

    # this is an abreviation so we save some typing
    # and get shorter lines
    bom = bpy.ops.mesh

    # we are starting with a circle
    bom.primitive_circle_add(vertices=8, radius=0.1)
    # switch to EDIT mode
    bpy.ops.object.mode_set(mode='EDIT')
    # start extruding the circle
    bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                            TRANSFORM_OT_translate={"value": (0, 0, 0)})

    # selekct all corners
    bom.edge_face_add()
    # closing to bottom
    bom.merge(type='CENTER', uvs=False)
    # select the vertices
    bom.select_all(action='INVERT')
    # aad new circles
    for idx in range(12):
        bom.extrude_region_move(
            MESH_OT_extrude_region={"mirror": False},
            TRANSFORM_OT_translate={"value": (0, 0, -0.05)}
        )
        # the new circle is aproximatly 30 % greater
        bpy.ops.transform.resize(value=(1.3, 1.3, 1.3))

    # divide the bottom cylinder of the bottle into two segements
    bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                            TRANSFORM_OT_translate={"value": (0, 0, 1)})
    bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                            TRANSFORM_OT_translate={"value": (0, 0, 1)})

    # multiple transformations with different sizes, to form a the bottle shape
    for idx in range(90, 60, -5):
        resize = idx/100.0
        bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                                TRANSFORM_OT_translate={"value": (0, 0, 0.5)})
        bpy.ops.transform.resize(value=(resize, resize, resize))

    # the bottleneck with two units up
    bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                            TRANSFORM_OT_translate={"value": (0, 0, 2)})

    bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                            TRANSFORM_OT_translate={"value": (0, 0, 0)})

    # a smaler part
    bpy.ops.transform.resize(value=(0.90, 0.90, 0.90))

    # the inner part of the bottle towards the bottom
    bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                            TRANSFORM_OT_translate={"value": (0, 0, -2)})

    for idx in range(60, 90, 5):
        pos = idx/100. + 0.60
        bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                                TRANSFORM_OT_translate={"value": (0, 0, -0.5)})
        bpy.ops.transform.resize(value=(pos, pos, pos))

        # move the inner part  1.9 units
        bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                                TRANSFORM_OT_translate={"value": (0, 0, -1.9)})
    # select the inner corners
    bom.edge_face_add()
    # innen den Flaschenboden extrudieren und nach oben ziehen
    for idx in range(65, 0, -5):
        pos = idx/100.0
        bom.extrude_region_move(MESH_OT_extrude_region={"mirror": False},
                                TRANSFORM_OT_translate={"value": (0, 0, 0.05)})
        bpy.ops.transform.resize(value=(pos, pos, pos))
    # innen die Ecken selektieren
    bom.edge_face_add()
    # innen den Flaschenboden schliesen
    bom.merge(type='CENTER', uvs=False)
    # in den Object Modus zurückwechseln
    bpy.ops.object.mode_set(mode='OBJECT')

if __name__ == '__main__':
    bottle()

Comments