コード例 #1
0
 def _writeScale(self, pbrtwriter: PbrtWriter, axis, s):
     org = (.5, .5, .5)
     pbrtwriter.translate(org)
     axis_v = {"x": (1, 0, 0), "y": (0, 1, 0), "z": (0, 0, 1)}
     sixa_v = {"x": (0, 1, 1), "y": (1, 0, 1), "z": (1, 1, 0)}
     pbrtwriter.scale(plus(mult(axis_v[axis], s), sixa_v[axis]))
     pbrtwriter.translate(mult(org, -1))
コード例 #2
0
    def _writeElement(self, pbrtwriter: PbrtWriter, ele, material):
        from_pt = ele["from"]
        to_pt = ele["to"]
        cube = minus(to_pt, from_pt)
        mid = mult(plus(from_pt, to_pt), .5)

        with pbrtwriter.attribute():
            pbrtwriter.translate(mid)
            if "rotation" in ele:
                import math
                rot = ele["rotation"]
                axis = rot["axis"]
                org = minus(mid, mult(rot["origin"], 1. / 16))
                ang = rot["angle"]
                rxyz = {"x": (1, 0, 0), "y": (0, 1, 0), "z": (0, 0, 1)}
                sxyz = {"x": (0, 1, 1), "y": (1, 0, 1), "z": (1, 1, 0)}
                pbrtwriter.translate(mult(org, -1))
                pbrtwriter.rotate(ang, rxyz[axis])
                if "rescale" in rot and rot["rescale"]:
                    scale = 1 / math.cos(ang / 180. * math.pi)
                    pbrtwriter.scale(plus(mult(sxyz[axis], scale), rxyz[axis]))
                pbrtwriter.translate(org)

            for facename in ele["faces"]:
                face = ele["faces"][facename]
                tex = face["texture"]
                uv = face["uv"]
                delta_f, l_f, dir_, shape = pt_map[facename]
                delta = delta_f(cube)
                l1, l2 = l_f(cube)
                with pbrtwriter.attribute():
                    if "rotation" in face:
                        rxyz = {"x": (1, 0, 0), "y": (0, 1, 0), "z": (0, 0, 1)}
                        # shape[-1] should be "x", "y" or "z"
                        pbrtwriter.rotate(face["rotation"] * dir_,
                                          rxyz[shape[-1]])

                    if material:
                        material.write(pbrtwriter, face)

                    pbrtwriter.translate(delta)
                    params = [
                        "float l1", [l1], "float l2", [l2], "float dir",
                        [dir_], "float u0", uv[0], "float v0", uv[1],
                        "float u1", uv[2], "float v1", uv[3]
                    ]
                    if ResourceManager().hasAlpha(tex + ".png"):
                        params.append("texture alpha")
                        params.append("%s-alpha" % tex)
                    pbrtwriter.shape(shape, *params)
コード例 #3
0
    def _writeMain(self, filename, scene_filename):
        fout = open(filename, "w")
        pbrtwriter = PbrtWriter(fout)

        # The coordinate system of minecraft and pbrt is different.
        # Pbrt is lefthand base, while minecraft is righthand base.
        pbrtwriter.scale((-1, 1, 1))

        pbrtwriter.film("image", "integer xresolution",
                        [self.resolution["Width"]], "integer yresolution",
                        [self.resolution["Height"]])

        pbrtwriter.lookAt(self.lookat_vec)

        self.camera.write(pbrtwriter)
        self.method.write(pbrtwriter)

        pbrtwriter.sampler("lowdiscrepancy", "integer pixelsamples",
                           [self.samples])

        with pbrtwriter.world():
            pbrtwriter.include(scene_filename)