labels

Übersicht: Blend4Web


Objectives

Not everyone knows the Berlin clock and know how they "tick"! Blend4Web has a nice solution to show description of objects. We want to show in this station, how it works and use a script to automate the settings.

Instructions

Tasks:
  1. Take an working example from the "Berlin Clock" tutorials.
  2. Create a new script for generating explanations.
  3. Review the result in the Fast Preview.
  4. Export the scene as a json file.
  5. Add the necessary HTML elements and scripts in a HTML page.
  6. Save all the necessary files in a test folder.
  7. Start a Web server and check the result.

Create labels is described in the manual. If the commands once performed and actions copied from the Info Window to a script, it is easy to add labels with information and it is reduced therefore to a few clicks!

Here is the script:

blend4web/labels/annotations-en.py (Source)

#! bpy
"""
Name: 'berlin-clock.py'
Blender: 27x
Group: 'Example'
Tooltip: 'Labelcreator--Blend4Web-Berlin-Clock'
"""
import bpy


def create_labels():
    "Create and compose labels for the berlin-clock"

    clock_labels = [["seconds",
                     "Seconds",
                     "Blinking every two seconds"],
                    ["hour_01",
                     "Hours",
                     "One element = five hours"],
                    ["hour_05",
                     "Hours",
                     "One element = one hour"],
                    ["minute_01",
                     "Minutes",
                     "One element = five min./all 15 min. an other color"],
                    ["minute_12",
                     "Minutes", "One element = one minute"]]

    scn = bpy.context.scene
    for row in clock_labels:
        cube = bpy.data.objects[row[0]]
        coords = cube.location
        bpy.ops.object.empty_add(type='PLAIN_AXES',
                                 location=(coords.x,
                                           coords.y,
                                           coords.z+1))

        obj = bpy.context.object
        obj.name = row[0]+"_label"
        obj.b4w_object_tags.title = row[1]
        obj.b4w_object_tags.description = row[2]
        obj.b4w_enable_object_tags = True
        obj.b4w_enable_anchor = True


if __name__ == '__main__':
    scn = bpy.context.scene
    for ob in scn.objects:
        if ob.type == 'EMPTY':
            scn.objects.unlink(ob)
            bpy.data.objects.remove(ob)

    create_labels()

Result

The steps 3 to 6 correspond to the steps of the previous learning station and are not repeated here.

Hint: Clicked on the label, to view the explanation, possibly the rotation must be stopped beforehand.
Remark: The clock turns, but the time still stands still!

Comments