Пример #1
0
 def __init__(self):
     self.mortar = []
     self.layer = []
     for j in range(0, 15):
         blocks = []
         for i in range(1, 6):
             blocks.append(self._get_block().add_args(["translate", [-2.4 + i * .8, j * 0.4 + .1, -0.2]]))
             blocks.append(self._get_block().add_args(["translate", [-2.4 + i * .8, j * 0.4 + .1, 0.2]]))
         blocks.append(
             self._get_block().add_args(["rotate", [0, 90, 0],
                                         "translate", [2.2, j * 0.4 + .1, 0.0]]))
         self.layer.append(blocks)
         color = (0.40, 0.45, 0.85)
         self.mortar.append(vapory.Box([-1.8, j * .4 - .01, -.385], [2.38, j * .4 + .185, .385],
                                       vapory.Texture(
                                           vapory.Pigment('color', [0.5 / 255. * e for e in (92, 71, 0)])),
                                       vapory.Finish("ambient", [.15 / 255. * e for e in color], "diffuse",
                                                     0.6)))
         blocks = []
         blocks.append(
             self._get_block().add_args(["rotate", [0, 90, 0],
                                         "translate", [-1.8, j * 0.4 + .3, 0.0]]))
         for i in range(1, 6):
             blocks.append(self._get_block().add_args(["translate", [-2.0 + i * .8, j * 0.4 + .3, -0.2]]))
             blocks.append(self._get_block().add_args(["translate", [-2.0 + i * .8, j * 0.4 + .3, 0.2]]))
         self.layer.append(blocks)
         color = (0.40, 0.45, 0.85)
         self.mortar.append(vapory.Box([-1.8, .19 + j * .4, -.385], [2.38, j * .4 + .385, .385],
                                       vapory.Texture(
                                           vapory.Pigment('color', [0.5 / 255. * e for e in (92, 71, 0)])),
                                       vapory.Finish("ambient", [.15 / 255. * e for e in color], "diffuse",
                                                     0.6)))
Пример #2
0
 def _get_block(self, x, y, z):
     p1 = [-x, -y, -z]
     p2 = [x, y, z]
     color = (75, 71, 0)
     return vp.Box(p1, p2, vp.Texture(vp.Pigment('color', [0.8/255. * e for e in color])),
                   vp.Finish("ambient", [1/255. * e for e in color], "diffuse",
                             0.0))
Пример #3
0
    def _get_block(self):
        return Block(.2, .05, .1,
                     0.025).get_block().add_args(["translate", [0, 0.05, 0]])

        color = (240 + random.randint(-5, 5), 180 + random.randint(-5, 5),
                 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))
Пример #4
0
    def __init__(self):
        self.blocks = []
        for i in range(-1, 2):
            block = self._get_block().add_args(["translate", [i * .4, .0, .7]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["translate", [i * .4, .0, -.7]])
            self.blocks.append(block)
            block = self._get_block().add_args(["translate", [i * .4, .2, .7]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["translate", [i * .4, .2, -.7]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["rotate", [0, 90, 0], "translate", [.7, 0.1, 0.4 * i]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["rotate", [0, 90, 0], "translate", [-.7, 0.1, 0.4 * i]])
            self.blocks.append(block)
        for i in range(-2, 2):
            block = self._get_block().add_args(
                ["rotate", [0, 90, 0], "translate", [.7, 0, 0.4 * i + .2]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["rotate", [0, 90, 0], "translate", [-.7, 0, 0.4 * i + .2]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["rotate", [0, 90, 0], "translate", [.7, 0.2, 0.4 * i + .2]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["rotate", [0, 90, 0], "translate", [-.7, 0.2, 0.4 * i + .2]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["translate", [0.4 * i + .2, 0.1, 0.7]])
            self.blocks.append(block)
            block = self._get_block().add_args(
                ["translate", [0.4 * i + .2, 0.1, -0.7]])
            self.blocks.append(block)

        color = (75, 71, 0)
        self.blocks.append(
            vapory.Box([-.79, 0, -0.79], [.79, 0.29, 0.79],
                       vapory.Texture(
                           vapory.Pigment('color',
                                          [0.8 / 255. * e for e in color])),
                       vapory.Finish("ambient", [1 / 255. * e for e in color],
                                     "diffuse", 0.0)))

        self.foundation = vapory.Union()
        self.foundation.args = self.blocks
        self.foundation = self.foundation.add_args(["scale", [2, 2, 2]])
Пример #5
0
    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],
        vapory.Texture(
            vapory.Pigment('color', [1.1 * e for e in [0.40, 0.45, 0.85]])),
        vapory.Finish('phong', 0.1))

    objects = [sun, sky, ground]
    Foundation().add_objects(objects)
    scene = vapory.Scene(camera,
                         objects,
                         included=['colors.inc', 'textures.inc'])
    scene.render('./images/foundation.png',
                 width=1200,
                 height=800,
                 antialiasing=.0001)
Пример #6
0
 def add_object(self, list, translate):
     list.append(vp.Intersection(self.body.add_args(["translate", translate]), vp.Box(
         [-20, 0, -20], [20, 20, 20]
     )))
Пример #7
0
def geometry_to_povray(appearance, geometry, object, transform, properties):
    if get_property_yes(properties, [geometry, object], "hide"):
        return []

    #analyze appearance
    tex = get_property(properties, [geometry, object], 'texture')
    if tex is None:
        tex_params = []
        #pigment
        pigment = get_property(properties, [geometry, object], 'pigment')
        if pigment is None:
            transmit = 1. - appearance.getColor()[3]
            pigment = vp.Pigment(*[
                'color',
                list(appearance.getColor())[0:3], 'transmit',
                get_property(properties, [geometry, object], 'ambient',
                             transmit)
            ])
        tex_params.append(pigment)

        #finish
        finish = get_property(properties, [geometry, object], 'finish')
        if finish is None:
            finish=vp.Finish(*['ambient',get_property(properties,[geometry,object],'ambient',0.2), \
                               'diffuse',get_property(properties,[geometry,object],'diffuse',0.7), \
                               'phong',get_property(properties,[geometry,object],'phong',1.),  \
                               'phong_size',get_property(properties,[geometry,object],'phong_size',50)])
        tex_params.append(finish)

        #normal
        normal = get_property(properties, [geometry, object], 'normal')
        if normal is not None:
            tex_params.append(normal)

        #texture
        tex = vp.Texture(*tex_params)

    #create geometry
    ret = []
    if transform is None:
        transform = geometry.getCurrentTransform()
    else:
        transform = se3.mul(transform, geometry.getCurrentTransform())
    if geometry.type() == "GeometricPrimitive":
        prim = geometry.getGeometricPrimitive()
        if get_property_yes(properties, [prim, geometry, object], "hide"):
            return ret
        if prim.type == "Point":
            rad = get_property(properties, [prim, geometry, object], "radius")
            if rad is not None:
                mesh_param = [se3.apply(transform, prim.properties[0:3]), rad]
                mesh_param.append(tex)
                mesh = vp.Sphere(*mesh_param)
                ret.append(mesh)
        elif prim.type == "Sphere":
            mesh_param = [
                se3.apply(transform, prim.properties[0:3]), prim.properties[3]
            ]
            mesh_param.append(tex)
            mesh = vp.Sphere(*mesh_param)
            ret.append(mesh)
        elif prim.type == "Segment":
            rad = get_property(properties, [prim, geometry, object], "radius")
            if rad is not None:
                mesh_param = [
                    se3.apply(transform, prim.properties[0:3]),
                    se3.apply(transform, prim.properties[3:6]), rad
                ]
                mesh_param.append(tex)
                mesh = vp.Cylinder(*mesh_param)
                ret.append(mesh)
        elif prim.type == "AABB":
            mesh_param = [
                se3.apply(transform, prim.properties[0:3]),
                se3.apply(transform, prim.properties[3:6])
            ]
            mesh_param.append(tex)
            mesh = vp.Box(*mesh_param)
            ret.append(mesh)
    elif geometry.type() == "Group":
        for idElem in range(geometry.numElements()):
            elem = geometry.getElement(idElem)
            elem.getCurrentTransform()
            ret += geometry_to_povray(appearance=appearance,
                                      geometry=elem,
                                      object=object,
                                      transform=transform,
                                      properties=properties)
    elif geometry.type() == "TriangleMesh":
        tm = geometry.getTriangleMesh()

        if get_property_yes(properties, [geometry, object], "smooth"):
            vss = [
                se3.apply(transform, tuple(tm.vertices[i * 3:i * 3 + 3]))
                for i in range(len(tm.vertices) // 3)
            ]
            iss = [
                tuple(tm.indices[i * 3:i * 3 + 3])
                for i in range(len(tm.indices) // 3)
            ]
            mesh_param = [
                vp.VertexVectors(*([len(vss)] + vss)),
                vp.FaceIndices(*([len(iss)] + iss))
            ]
            mesh_param.append(tex)
            mesh = vp.Mesh2(*mesh_param)
        else:
            vss = [
                se3.apply(transform, tuple(tm.vertices[i * 3:i * 3 + 3]))
                for i in range(len(tm.vertices) // 3)
            ]
            iss = [
                tuple(tm.indices[i * 3:i * 3 + 3])
                for i in range(len(tm.indices) // 3)
            ]
            mesh_param = [
                vp.Triangle(vss[it[0]], vss[it[1]], vss[it[2]]) for it in iss
            ]
            mesh_param.append(tex)
            mesh = vp.Mesh(*mesh_param)

        ret.append(mesh)
    elif geometry.type() == "VolumeGrid":
        from skimage import measure
        import numpy as np
        grid = geometry.getVolumeGrid()
        volume = np.reshape(np.array(list(grid.values)), tuple(grid.dims))
        spacing = [
            (b - a) / d
            for a, b, d in zip(grid.bbox[0:3], grid.bbox[3:6], grid.dims[0:3])
        ]
        vss, iss, nss, _ = measure.marching_cubes_lewiner(volume,
                                                          level=0.,
                                                          spacing=spacing)
        vss += np.expand_dims(np.array(grid.bbox[0:3]).T, 0)
        vss = [vss[it, :].tolist() for it in range(vss.shape[0])]
        iss = [iss[it, :].tolist() for it in range(iss.shape[0])]
        nss = [nss[it, :].tolist() for it in range(nss.shape[0])]
        mesh_param = [
            vp.VertexVectors(*([len(vss)] + vss)),
            vp.NormalVectors(*([len(nss)] + nss)),
            vp.FaceIndices(*([len(iss)] + iss))
        ]
        mesh_param.append(tex)
        mesh = vp.Mesh2(*mesh_param)
        ret.append(mesh)
    elif geometry.type() == "PointCloud":
        cloud_param = []
        cloud = geometry.getPointCloud()
        rad = get_property(properties, [cloud, geometry, object], "radius")
        for id in range(len(cloud.vertices) // 3):
            cloud_param.append(
                vp.Sphere(cloud.vertices[id * 3:id * 3 + 3], rad))
        cloud_param.append(tex)
        mesh = vp.Union(*cloud_param)
        ret.append(mesh)
    else:
        print("Geometry (name=%s) type: %s not supported!" %
              (object.getName(), geometry.type()))
    return ret
Пример #8
0
import vapory.vapory as vp

from Tools import StickMan, MakeTree

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([-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)
Пример #9
0
    def __init__(self, dict_of_angles, crossarm=False, falda=False):
        width = 0.07
        right_pelvis = [width, 0, 0]
        left_pelvis = [-width, 0, 0]
        rad = (dict_of_angles["torso"]) * math.pi / 180.
        neck = [1.5 * width, 0 - 0.6 * math.cos(rad), 0.6 * math.sin(rad)]
        right_shoulder = [1.5 * width, neck[1], neck[2]]
        left_shoulder = [- 1.5 * width, neck[1], neck[2]]
        self.left_shoulder = left_shoulder
        right_knee = self.get_point(right_pelvis, dict_of_angles["thigh_1"], 0, .5)
        right_foot = self.get_point(right_knee, dict_of_angles["shin_1"], 0, .5)
        left_knee = self.get_point(left_pelvis, dict_of_angles["thigh_2"], 0, .5)
        left_foot = self.get_point(left_knee, dict_of_angles["shin_2"], 0, .5)
        left_elbow = self.get_point(left_shoulder, dict_of_angles["upper_arm1"], 0, .4)
        left_elbow = (left_elbow[0] - 0.04, left_elbow[1], left_elbow[2])
        left_hand = self.get_point(left_elbow, dict_of_angles["lower_arm1"], 0, .4)
        right_elbow = self.get_point(right_shoulder, dict_of_angles["upper_arm2"], -0, .4)
        right_elbow = (right_elbow[0] + 0.04, right_elbow[1], right_elbow[2])
        right_hand = self.get_point(right_elbow, dict_of_angles["lower_arm2"], -0, .4)
        if crossarm:
            left_hand = (-left_hand[0], left_hand[1], left_hand[2])
        self.left_hand = left_hand
        self.right_hand = right_hand

        texture = vapory.Texture(vapory.Pigment('color', [0.0 * e for e in [0.20, 0.20, 0.20]]),
                                 vapory.Finish('phong', 0.0))
        deg = (dict_of_angles["torso"])
        self.torso = vapory.Box([-width, 0, -width / 2], [width, 0.6, width / 2], texture,
                                "rotate", [-deg - 180, 0, 0],
                                "translate", [0, 0, 0])
        self.lower_left_leg = self.get_rounded_cylinder(left_knee, left_foot, 0.07 / 2, texture)
        self.upper_left_leg = self.get_rounded_cylinder(left_pelvis, left_knee, 0.07 / 2, texture)
        self.lower_right_leg = self.get_rounded_cylinder(right_knee, right_foot, 0.07 / 2, texture)
        self.upper_right_leg = self.get_rounded_cylinder(right_pelvis, right_knee, 0.07 / 2, texture)
        self.hip = self.get_rounded_cylinder(left_pelvis, right_pelvis, 0.07 / 2, texture)
        self.left_flank = self.get_rounded_cylinder([-width, 0, 0], [-width, neck[1], neck[2]], 0.07 / 2, texture)
        self.right_flank = self.get_rounded_cylinder([width, 0, 0], [width, neck[1], neck[2]], 0.07 / 2, texture)
        self.shoulder = self.get_rounded_cylinder(left_shoulder, right_shoulder, width / 2, texture)
        self.upper_left_arm = self.get_rounded_cylinder(left_shoulder, left_elbow, width / 2, texture)
        self.lower_left_arm = self.get_rounded_cylinder(left_elbow, left_hand, width / 2, texture)
        self.upper_right_arm = self.get_rounded_cylinder(right_shoulder, right_elbow, width / 2, texture)
        self.lower_right_arm = self.get_rounded_cylinder(right_elbow, right_hand, width / 2, texture)
        rad = (dict_of_angles["head"]) * math.pi / 180.
        self.head = vapory.Sphere(
            [0, neck[1] - (0.35 / 2 + width) * math.cos(rad), neck[2] + (0.35 / 2 + width) * math.sin(rad)], 0.35 / 2,
            texture)
        self.body = vapory.Union(self.torso, self.lower_left_leg, self.upper_left_leg, self.lower_right_leg,
                                 self.upper_right_leg, self.hip, self.left_flank, self.right_flank, self.shoulder,
                                 self.upper_left_arm, self.lower_left_arm, self.upper_right_arm, self.lower_right_arm,
                                 self.head)
        if (falda):
            falda = vapory.Triangle(left_pelvis, left_knee, right_knee, texture)
            self.body.args.append(falda)
            p1 = [0, neck[1] - (2.72 - 2.96), neck[2] + 1.57 - 1.74]
            p2 = [0, neck[1] - (3.17 - 2.96), neck[2] + 1.60 - 1.74]
            p3 = [0, neck[1] - (2.72 - 2.96), neck[2] + 1.68 - 1.74]
            hair = vapory.Triangle(p1, p2, p3, texture)
            hair = hair.add_args(["rotate", [0 * 180. / math.pi * rad, 0, 0]])
            self.body.args.append(hair)
            p1 = [0, neck[1] - (3.01 - 2.96), neck[2] + 1.62 - 1.74]
            p2 = [0, neck[1] - (3.26 - 2.96), neck[2] + 1.59 - 1.74]
            p3 = [0, neck[1] - (3.26 - 2.96), neck[2] + 1.54 - 1.74]
            hair = vapory.Triangle(p1, p2, p3, texture)
            hair = hair.add_args(["rotate", [0 * 180. / math.pi * rad, 0, 0]])
            self.body.args.append(hair)
            p1 = [0, neck[1] - (3.26 - 2.96), neck[2] + (1.59 + 1.54) / 2. - 1.74]
            hair = vapory.Sphere(p1, 0.025, texture)
            hair = hair.add_args(["rotate", [0 * 180. / math.pi * rad, 0, 0]])
            self.body.args.append(hair)
        # self.body = self.body.add_args(["scale", [0.5, 0.5, 0.5]])
        pos = dict_of_angles["pos"]
        self.body = self.body.add_args(["translate", [0, pos[1], pos[0]]])
Пример #10
0
    camera = vapory.Camera('orthographic', 'angle', 50,
                           'location', [10.0, 1.0, 0.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([-4, 0, -4], [4, -0.1, 4],
                        vapory.Texture(vapory.Pigment('color', [1.1 * e for e in [0.40, 0.45, 0.85]])),
                        vapory.Finish('phong', 0.1))

    frames = pickle.load(open("frames.p", "rb"))
    i = 0
    for frame in frames:
        def getOrientation(pos1, pos2):
            return math.atan2(pos2[0] - pos1[0], -pos2[1] + pos1[1])


        pos = (frame["crotch"][0] - 216) / 100.
        thigh_1 = -180. / math.pi * getOrientation(frame["knee_1"], frame["crotch"])
        thigh_2 = -180. / math.pi * getOrientation(frame["knee_2"], frame["crotch"])
        shin_1 = -180. / math.pi * getOrientation(frame["foot_1"], frame["knee_1"])
        shin_2 = -180. / math.pi * getOrientation(frame["foot_2"], frame["knee_2"])
        upper_arm1 = -180. / math.pi * getOrientation(frame["elbow_1"], frame["neck"])
Пример #11
0
 def _get_box(self, p1, p2, color) -> vp.Box:
     return vp.Box(
         p1, p2,
         vp.Texture(vp.Pigment('color', [1. / 255. * e for e in color])),
         vp.Finish("ambient", 1.0, "diffuse", 0.0))
Пример #12
0
import vapory.vapory as vp

from Tools import StickMan, Flag, MakeTree

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([-4.36, 0, -6.1], [4.36, -0.05, 3.85],
                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 * 5],
                     '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])

datas = pickle.load(open("./data/final.dat", "rb"))

box = vp.Box([-10, 0, -10], [10, 10, 10])