Ejemplo n.º 1
0
                 75 + random.randint(-5, 5))
        return vapory.Box(
            [-0.195, 0, -0.095], [.195, 0.095, 0.095],
            vapory.Texture(
                vapory.Pigment('color', [0.5 * 1. / 255. * e for e in color])),
            vapory.Finish("ambient", 0.1, "diffuse", 0.6))

    def add_objects(self, list):
        # pass
        list.append(self.foundation)
        # for block in self.blocks:
        #    list.append(block)


if __name__ == "__main__":
    camera = vapory.Camera('orthographic', 'angle', 50, 'location',
                           [5.0, 6.0, 5.0], 'look_at', [0.0, 1.0, 0.0])

    sun = vapory.LightSource([1500, 2500, 2500], 'color', 1)

    sky = vapory.Sphere([0, 0, 0], 1, 'hollow',
                        vapory.Texture(
                            vapory.Pigment(
                                'gradient', [0, 1, 0],
                                vapory.ColorMap([0, 'color', 'White'],
                                                [1, 'color', 'White']),
                                'quick_color', 'White'),
                            vapory.Finish('ambient', 1, 'diffuse', 0)),
                        'scale', 10000)

    ground = vapory.Box(
        [-2, 0, -2], [2, -0.05, 2],
Ejemplo n.º 2
0
def to_povray(vis, world, properties={}):
    """Convert a frame in klampt visualization to a povray script (or render
    to an image)

    Args:
        vis: sub-class of GLProgram
        world: sub-class of WorldModel
        properties: some additional information that povray can take but does
            not map to anything in klampt.
    
    Note::
        Do not modify properties, use the convenience functions that I provide 
        below (after this function).  These take the form ``render_to_x`` and
        ``add_x``.
    """
    #patch on vapory
    patch_vapory()

    #camera
    mat = vis.view.camera.matrix()
    pos = mat[1]
    right = mat[0][0:3]
    up = mat[0][3:6]
    dir = op.mul(mat[0][6:9], -1)
    tgt = op.add(mat[1], dir)
    #scale
    fovy = vis.view.fov * vis.view.h / vis.view.w
    fovx = math.atan(vis.view.w * math.tan(fovy * math.pi / 360.) /
                     vis.view.h) * 360. / math.pi
    right = op.mul(right, -float(vis.view.w) / vis.view.h)
    #camera
    camera_params = [
        'orthographic' if vis.view.orthogonal else 'perspective', 'location',
        [pos[0], pos[1], pos[2]], 'look_at', [tgt[0], tgt[1], tgt[2]], 'right',
        [right[0], right[1], right[2]], 'up', [up[0], up[1], up[2]], 'angle',
        fovx, 'sky',
        get_property(properties, [], "sky", [0., 0., 1.])
    ]
    camera = vp.Camera(*camera_params)

    #tempfile
    tempfile = get_property(properties, [], "tempfile", None)
    tempfile_path = os.path.dirname(tempfile) if tempfile is not None else '.'
    if not os.path.exists(tempfile_path):
        os.mkdir(tempfile_path)

    #objects
    objects = []
    objs = [o for o in properties["visualObjects"]
            ] if "visualObjects" in properties else []
    objs += [world.terrain(i) for i in range(world.numTerrains())]
    objs += [world.rigidObject(i) for i in range(world.numRigidObjects())]
    for r in range(world.numRobots()):
        objs += [
            world.robot(r).link(i) for i in range(world.robot(r).numLinks())
        ]
    for obj in objs:
        transient = get_property(properties, [obj], "transient", default=True)
        if transient:
            objects += geometry_to_povray(obj.appearance(),
                                          obj.geometry(),
                                          obj,
                                          None,
                                          properties=properties)
        else:
            path = tempfile_path + '/' + obj.getName() + '.pov'
            if not os.path.exists(path):
                R, t = obj.geometry().getCurrentTransform()
                obj.geometry().setCurrentTransform([1, 0, 0, 0, 1, 0, 0, 0, 1],
                                                   [0, 0, 0])
                geom = geometry_to_povray(obj.appearance(),
                                          obj.geometry(),
                                          obj,
                                          None,
                                          properties=properties)
                if len(geom) > 1:
                    file_content = vp.Union(*geom)
                elif len(geom) > 0:
                    file_content = vp.Object(*geom)
                else:
                    file_content = None
                if file_content is not None:
                    f = open(path, 'w')
                    f.write(str(file_content))
                    f.close()
                    obj.geometry().setCurrentTransform(R, t)
                else:
                    path = None
            #include
            if path is not None:
                R, t = obj.geometry().getCurrentTransform()
                objects.append(
                    vp.Object('#include "%s"' % path, "matrix", R + t))

    #light
    if "lights" in properties:
        objects += properties["lights"]

    #scene
    gsettings = []
    scene = vp.Scene(camera=camera,
                     objects=objects,
                     included=get_property(properties, [], "included", []),
                     global_settings=get_property(properties, [],
                                                  "global_settings", []))
    try:
        #this works with later version of vapory
        return  \
        render_povstring(str(scene),   \
                     outfile=get_property(properties,[],"outfile",None),  \
                     width=vis.view.w,height=vis.view.h,    \
                     quality=get_property(properties,[],"quality",None),    \
                     antialiasing=get_property(properties,[],"antialiasing",0.3),    \
                     remove_temp=get_property(properties,[],"remove_temp",False),    \
                     show_window=get_property(properties,[],"show_window",False),     \
                     tempfile=tempfile, \
                     includedirs=get_property(properties,[],"includedirs",None),    \
                     output_alpha=get_property(properties,[],"output_alpha",True))
    except:
        #this works with earlier version of vapory
        return  \
        render_povstring(str(scene),   \
                     outfile=get_property(properties,[],"outfile",None),  \
                     width=vis.view.w,height=vis.view.h,    \
                     quality=get_property(properties,[],"quality",None),    \
                     antialiasing=get_property(properties,[],"antialiasing",0.3),    \
                     remove_temp=get_property(properties,[],"remove_temp",False))
Ejemplo n.º 3
0
sky = vp.Sphere([0, 0, 0], 1, 'hollow',
                vp.Texture(vp.Pigment('gradient', [0, 1, 0],
                                      vp.ColorMap([0, 'color', 'White'],
                                                  [1, 'color', 'White']),
                                      'quick_color', 'White'),
                           vp.Finish('ambient', 1, 'diffuse', 0)),
                'scale', 10000)

ground = vp.Box([-4.36, 0, -4.36], [4.36, -0.05, 4.36],
                vp.Texture(vp.Pigment('color', [1.1 * e for e in [0.40, 0.45, 0.85]])),
                vp.Finish('phong', 0.1))

objects = [sun, ground, sky]

camera_1 = vp.Camera('orthographic', 'angle', 2 * 180 / math.pi * math.atan2(6.4, 5),
                     'location', [5.0, 2.31, 0],
                     'look_at', [0.0, 2.31, 0.0])

camera_2 = vp.Camera('orthographic', 'angle', 50,
                     'location', [10, 11, 10],
                     'look_at', [0.0, 1, 0.0])

data = pickle.load(open("./data/dream.dat", "rb")).pop()

data["stickman_1"]["pos"]=  (data["stickman_1"]["pos"][0], data["stickman_1"]["pos"][1]+0.325)
data["stickman_2"]["pos"]=  (data["stickman_2"]["pos"][0], data["stickman_2"]["pos"][1]+0.325)
data["stickman_3"]["pos"]=  (data["stickman_3"]["pos"][0], data["stickman_3"]["pos"][1]+0.325)

objects_a = objects.copy()
MakeTree.scene(0, objects_a)
tree = objects_a.pop()
Ejemplo n.º 4
0
        union.args = elems
        return union

    def _get_cylinder(self, start, end, radius, texture):
        c1 = vp.Sphere(start, radius, texture)
        c2 = vp.Sphere(end, radius, texture)
        c3 = vp.Cylinder(start, end, radius, texture)
        return vp.Union(c1, c2, c3)

    def add_object(self, list):
        list.append(self.body.add_args(["rotate", [self.orientation, 0, 0], "translate", self.position]))


if __name__ == "__main__":
    camera = vp.Camera('orthographic', 'angle', 50,
                       'location', [3.0, .5, -0.0],
                       'look_at', [0.0, .5, 0.0])

    sun = vp.LightSource([1500, 2500, 2500], 'color', 1)

    sky = vp.Sphere([0, 0, 0], 1, 'hollow',
                    vp.Texture(vp.Pigment('gradient', [0, 1, 0],
                                          vp.ColorMap([0, 'color', 'White'],
                                                      [1, 'color', 'White']),
                                          'quick_color', 'White'),
                               vp.Finish('ambient', 1, 'diffuse', 0)),
                    'scale', 10000)

    ground = vp.Box([-2, 0, -2], [2, -0.05, 2],
                    vp.Texture(vp.Pigment('color', [1.1 * e for e in [0.40, 0.45, 0.85]])),
                    vp.Finish('phong', 0.1))
Ejemplo n.º 5
0
        string_list = [
            "function {}u + 0.05*u * sin(6*v+{}){} ".format("{", a + b, "}")
        ]
        string_list.append(
            "function {}v*(1-0.1*u) + sin(min(4*u,3.14159/2))*(0.025 * sin(10 * u + {})+0.025*sin(19 * u + {})+0.0015*sin(39*u) -(1-cos(0.4*u))){} "
            .format("{", a, b, "}"))
        string_list.append(
            "function {}0.02 * sin(10 * u)+0.02*sin(19*u)+0.25* u *  sin(6*v+{}){} "
            .format("{", a + b, "}"))
        string_list.append("<0,0>, <1,1> ")
        string_list.append("contained_by {sphere{0, 10}} ")
        return "".join(string_list)


if __name__ == "__main__":
    camera = vp.Camera('orthographic', 'angle', 50, 'location',
                       [1.4 * 5.0, 1.0, 0 * 5.0], 'look_at', [0.0, 1.0, 0.0])

    sun = vp.LightSource([1500, 2500, 2500], 'color', 1)

    sky = vp.Sphere([0, 0, 0], 1, 'hollow',
                    vp.Texture(
                        vp.Pigment(
                            'gradient', [0, 1, 0],
                            vp.ColorMap([0, 'color', 'White'],
                                        [1, 'color', 'White']),
                            'quick_color', 'White'),
                        vp.Finish('ambient', 1, 'diffuse', 0)), 'scale', 10000)

    ground = vp.Box([-2, 0, -2], [2, -0.05, 2],
                    vp.Texture(
                        vp.Pigment('color',