index

Übersicht: Blend4Web


Create a new script

/blend4web/berlin-clock/bc-scripting.png

The script

blend4web/berlin-clock/clockgenerator.py (Source)

#! bpy
"""
Name: 'berlin-clock.py'
Blender: 27x
Group: 'Example'
Tooltip: 'Construct a berlin-clock'
"""
import bpy
import random

clock = [["seconds"],
         ["hour_01", "hour_02", "hour_03", "hour_04"],
         ["hour_05", "hour_06", "hour_07", "hour_08"],
         ["minute_01", "minute_02", "minute_03", "minute_04"] +
         ["minute_05", "minute_06", "minute_07", "minute_08"] +
         ["minute_09", "minute_10", "minute_11"],
         ["minute_12", "minute_13", "minute_14", "minute_15"]]

MATERIAL= bpy.data.materials.get('Material')

def create(object):
    "Create and compose a berlin-clock"

    scn = bpy.context.scene
    rows = len(object)
    distances = [9.5, 3.75, 3.75, 1.6, 3.75]
    for row in range(rows):
        cols = len(object[row])
        for col in range(cols):
            distance = distances[row]
            x = row  * 3
            y = col * distance + distance
            obj = bpy.ops.mesh.primitive_cube_add(location=(x, y, 0))

            if row == 3:
                bpy.ops.transform.resize(value=(0.5, 0.5, 0.5))

            obj = bpy.context.object
            obj.name = clock[row][col]
            setColor(obj, MATERIAL, (0.12, .45, .50))
            obj.b4w_do_not_batch = True


def setColor(obj, material, color=None):
    """
    Meine Grundfarbe:
    Hex: 61B3BC,
    RGB: (0.12, .45, .50)
    """
    obj.data.materials.append(material)

def set_camera():
    scn = bpy.context.scene
    scn.objects.active = scn.objects['Camera']
    bpy.context.object.location[0] = 23
    bpy.context.object.location[1] = 25
    bpy.context.object.location[2] = 9

def create_node_material():
    """ RGB input for node material"""

    mat = MATERIAL
    mat.use_nodes = True
    nodes = mat.node_tree.nodes
    # Add a diffuse shader and set its location:
    rgb = nodes.new('ShaderNodeRGB')
    rgb.location = (-300,300)
    mat_node = nodes["Material"]
    mat.node_tree.links.new(mat_node.inputs[0], rgb.outputs[0])

if __name__ == '__main__':
    bpy.ops.object.select_by_type(type='MESH')
    bpy.ops.object.delete()
    create(clock)
    set_camera()
    #create_node_material()

Run script

/blend4web/berlin-clock/bc-scripting-run-script.png

Result from script

/blend4web/berlin-clock/bc-scripting-result-script.png

Result (rendered Image)

/blend4web/berlin-clock/bc-render-result.png

Comments