示例#1
0
    def export(cls, file):
        """Export all the rivers from the rivers list."""
        for river in River.list[:]:
            if not river.ref:
                River.list.remove(river)
                continue

            if WebotsObject.removalRadius > 0.0:
                # Check that the river is inside the scope of a road,
                # otherwise, remove it from the river list.
                if not Road.are_coords_close_to_some_road_waypoint(river.ref):
                    River.list.remove(river)
                    continue

            if not river.name == "":
                file.write("DEF " + protect_def_name(river.name) + " " +
                           "Transform {\n")
            else:
                file.write("Transform {\n")
            file.write("  translation %.2lf %.2lf %.2lf\n" %
                       (OSMCoord.coordDictionnary[river.ref[0]].x,
                        OSMCoord.coordDictionnary[river.ref[0]].y,
                        OSMCoord.coordDictionnary[river.ref[0]].z))
            file.write("  children [\n")
            file.write("    Shape {\n")
            file.write("      appearance PBRAppearance {\n")
            file.write("        baseColor 0.3 0.5 0.8\n")
            file.write("        roughness 0.3\n")
            file.write("        metalness 0\n")
            file.write("      }\n")
            file.write("      geometry Extrusion {\n")
            file.write("        crossSection [\n")
            file.write("          %.2f 0\n" % (-river.width / 2))
            file.write("          %.2f 0.5\n" % (-river.width / 2))
            file.write("          %.2f 0.5\n" % (river.width / 2))
            file.write("          %.2f 0\n" % (river.width / 2))
            file.write("          %.2f 0\n" % (-river.width / 2))
            file.write("        ]\n")
            file.write("        spine [\n")
            for ref in river.ref:
                if ref in OSMCoord.coordDictionnary:
                    file.write("          %.2f %.2f %.2f,\n" %
                               (OSMCoord.coordDictionnary[ref].x -
                                OSMCoord.coordDictionnary[river.ref[0]].x,
                                OSMCoord.coordDictionnary[ref].y -
                                OSMCoord.coordDictionnary[river.ref[0]].y,
                                OSMCoord.coordDictionnary[ref].z -
                                OSMCoord.coordDictionnary[river.ref[0]].z))
                else:
                    print("Warning: node " + str(ref) + " not referenced.")
            file.write("  ]\n")

            file.write("          splineSubdivision 0\n")
            file.write("      }\n")
            file.write("      castShadows FALSE\n")
            file.write("    }\n")
            file.write("  ]\n")
            file.write("}\n")
示例#2
0
文件: area.py 项目: woundet/webots
    def export(cls, file, noParkings):
        """Export all the areas from the areas list."""
        for area in Area.list[:]:
            if noParkings and area.type == 'parking':
                Area.list.remove(area)
                continue

            if WebotsObject.removalRadius > 0.0:
                # Check that the area is inside the scope of a road,
                # otherwise, remove it from the area list.
                if not Road.are_coords_close_to_some_road_waypoint(area.ref):
                    Area.list.remove(area)
                    continue

            defName = ""
            if not area.name == "":
                defName = area.name
            else:
                defName = area.type
            defName = protect_def_name(defName)
            if area.type == 'forest' and not Area.noForests:
                treesFile = area.generate_tree_file(os.path.dirname(os.path.abspath(file.name)))
                if file is not None:
                    file.write("Forest {\n")
                    file.write("  shape [\n")
                    if Area.are_references_clockwise(area.ref) is False:
                        for ref in area.ref:
                            file.write("    %.2f %.2f, " % (OSMCoord.coordDictionnary[ref].x, OSMCoord.coordDictionnary[ref].z))
                    else:
                        for ref in reversed(area.ref):
                            file.write("    %.2f %.2f, " % (OSMCoord.coordDictionnary[ref].x, OSMCoord.coordDictionnary[ref].z))
                    file.write("\n]\n")
                    if area.leafType == "needleleaved":
                        file.write(' type "%s"\n' % random.choice(Tree.needleLeavesTypes))
                    elif area.leafType == "broadleaved":
                        file.write(' type "%s"\n' % random.choice(Tree.broadLeavesTypes))
                    else:
                        file.write("  type \"random\"\n")
                    file.write("  treesFiles [\n")
                    file.write("    " + "\"" + treesFile + "\"" + "\n")
                    file.write("  ]\n")
                    file.write("}\n")
            else:
                verticalOffset = -0.01 if area.type == 'parking' else 0.0
                drawFlat = True if area.type == 'water' else False
                Area.draw_area(file, area.ref, area.color[0], area.color[1], area.color[2], defName, area.transparency,
                               area.texture, verticalOffset=verticalOffset, drawFlat=drawFlat)