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)
def write(self, pbrtwriter: PbrtWriter): with pbrtwriter.attribute(): pbrtwriter.rotate(270, [1, 0, 0]) pbrtwriter.lightSource("infinite", "integer nsamples", [16], "rgb L", [1, 1, 1], "string mapname", [self.filename])
def _writeRotate(self, pbrtwriter: PbrtWriter, axis, ang): org = (.5, .5, .5) pbrtwriter.translate(org) rxyz = {"x": (1, 0, 0), "y": (0, 1, 0), "z": (0, 0, 1)} pbrtwriter.rotate(ang, rxyz[axis]) pbrtwriter.translate(mult(org, -1))