Esempio n. 1
0
def ldr2pov(ldraw_path, pov_path, camera_position, look_at_position, sky):
    """ actual ldr2pov implementation """
    model, parts = get_model(ldraw_path)

    with open(pov_path, "w") as pov_file:
        pov_file.write('#include "include/colors.inc"\n\n')
        writer = POVRayWriter(parts, pov_file)
        writer.write(model)

        dd = camera_position.repr
        dd = dd.split(',')
        tt1 = float(dd[0])
        tt2 = float(dd[1])
        tt3 = float(dd[2])

        if not writer.lights:
            lights = (tt1, tt2, tt3, tt1, tt2, tt3, tt1, tt2, tt3, tt1, tt2,
                      tt3)
            pov_file.write(LIGHT_FORMAT_STRING % lights)

        pov_file.write(CAMERA_FORMAT_STRING %
                       (camera_position.repr, look_at_position.repr))

        if sky:
            pov_file.write(SKY_SPHERE_FORMAT_STRING % sky)

    for message, part in writer.warnings:
        sys.stderr.write((message + "\n") % part)
Esempio n. 2
0
def ldr2pov(ldraw_path, pov_path, camera_position, look_at_position, sky):
    """ actual ldr2pov implementation """
    model, parts = get_model(ldraw_path)

    with open(pov_path, "w") as pov_file:
        pov_file.write('#include "colors.inc"\n\n')
        writer = POVRayWriter(parts, pov_file)
        writer.write(model)

        if not writer.lights:
            lights = (writer.minimum.x - 50.0, writer.maximum.y + 100.0,
                      writer.minimum.z - 50.0, writer.maximum.x + 50.0,
                      writer.maximum.y + 100.0, writer.minimum.z - 50.0,
                      writer.minimum.x - 50.0, writer.maximum.y + 100.0,
                      writer.maximum.z + 50.0, writer.maximum.x + 50.0,
                      writer.maximum.y + 100.0, writer.maximum.z + 50.0)
            pov_file.write(LIGHT_FORMAT_STRING % lights)

        pov_file.write(CAMERA_FORMAT_STRING %
                       (camera_position.repr, look_at_position.repr))

        if sky:
            pov_file.write(SKY_SPHERE_FORMAT_STRING % sky)

    for message, part in writer.warnings:
        sys.stderr.write((message + "\n") % part)
Esempio n. 3
0
def ldr2png(ldraw_path, png_path, look_at_position, camera_position, png_args):
    """ Implementation of ldr2png """
    verify_camera_look_at(camera_position, look_at_position)

    model, parts = get_model(ldraw_path)

    system = get_coordinate_system(camera_position, look_at_position)

    writer = PNGWriter(camera_position, system, parts)
    writer.write(model, png_path, png_args)
Esempio n. 4
0
def ldr2svg(ldraw_path, svg_path, camera_position, look_at_position, svg_args):  # pylint: disable=too-many-arguments
    """ ldr2svg actual implementation """
    verify_camera_look_at(camera_position, look_at_position)

    model, parts = get_model(ldraw_path)

    system = get_coordinate_system(camera_position, look_at_position)

    with open(svg_path, "w") as svg_file:
        from ldraw.writers.svg import SVGWriter
        writer = SVGWriter(camera_position, system, parts)
        writer.write(model, svg_file, svg_args)
Esempio n. 5
0
def ldr2inv(ldraw_path, inventory_path):
    """ Actual ldr2inv implementation """
    model, parts = get_model(ldraw_path)

    inventory = {}
    length = 0

    for obj in model.objects:
        if not isinstance(obj, Piece):
            continue

        name = ""
        subpart = parts.part(code=obj.part)
        if subpart:
            for component in subpart.objects:
                if isinstance(component, Comment):
                    name = component.text
                    break
            else:
                sys.stderr.write("No name information for part: %s\n" %
                                 obj.text)

            inventory[name] = inventory.get(name, 0) + 1
            length = max(len(name), length)

    length += (4 - (length % 4))

    try:
        with codecs.open(inventory_path, 'w', encoding='utf-8') as inv_file:
            items = list(inventory.items())
            items.sort()

            for name, number in items:
                padding = " " * (length - len(name))
                inv_file.write("%s%s%i\n" % (name, padding, number))

    except IOError:
        sys.stderr.write("Failed to write inventory file: %s\n" %
                         inventory_path)
        sys.exit(1)