# Path: psychoblend/util.py
# def escape_name(name):
#     name = name.replace("\\", "\\\\")
#     name = name.replace(" ", "\\ ")
#     name = name.replace("$", "\\$")
#     name = name.replace("[", "\\[")
#     name = name.replace("]", "\\]")
#     name = name.replace("{", "\\{")
#     name = name.replace("}", "\\}")
#     return name
# 
# def mat2str(m):
#     """ Converts a matrix into a single-line string of values.
#     """
#     s = ""
#     for j in range(4):
#         for i in range(4):
#             s += (" %f" % m[i][j])
#     return s[1:]
# 
# class ExportCancelled(Exception):
#     """ Indicates that the render was cancelled in the middle of exporting
#         the scene file.
#     """
#     pass


import bpy
from math import degrees, tan, atan
from mathutils import Vector, Matrix
from .util import escape_name, mat2str, ExportCancelled

        # Dof distance
        if self.ob.data.dof_object == None:
            self.focal_distances += [self.ob.data.dof_distance]
        else:
            # TODO: implement DoF object tracking here
            self.focal_distances += [0.0]
            print("WARNING: DoF object tracking not yet implemented.")

        # Transform
        mat = self.ob.matrix_world.copy()
        matz = Matrix()
        matz[2][2] = -1
        self.xforms += [mat * matz]

    def export(self, render_engine, w):
        render_engine.update_stats("", "Psychopath: Exporting %s" % self.ob.name)
        w.write("Camera {\n")
        w.indent()

        for fov in self.fovs:
            w.write("Fov [%f]\n" % fov)

        for rad in self.aperture_radii:
            w.write("ApertureRadius [%f]\n" % rad)

        for dist in self.focal_distances:
            w.write("FocalDistance [%f]\n" % dist)

        for mat in self.xforms:

# Path: psychoblend/util.py
# def escape_name(name):
#     name = name.replace("\\", "\\\\")
#     name = name.replace(" ", "\\ ")
#     name = name.replace("$", "\\$")
#     name = name.replace("[", "\\[")
#     name = name.replace("]", "\\]")
#     name = name.replace("{", "\\{")
#     name = name.replace("}", "\\}")
#     return name
# 
# def mat2str(m):
#     """ Converts a matrix into a single-line string of values.
#     """
#     s = ""
#     for j in range(4):
#         for i in range(4):
#             s += (" %f" % m[i][j])
#     return s[1:]
# 
# class ExportCancelled(Exception):
#     """ Indicates that the render was cancelled in the middle of exporting
#         the scene file.
#     """
#     pass


# Path: psychoblend/world.py
import bpy
from math import degrees, tan, atan
from mathutils import Vector, Matrix
from .util import escape_name, mat2str, ExportCancelled


        # Dof distance
        if self.ob.data.dof_object == None:
            self.focal_distances += [self.ob.data.dof_distance]
        else:
            # TODO: implement DoF object tracking here
            self.focal_distances += [0.0]
            print("WARNING: DoF object tracking not yet implemented.")

        # Transform
        mat = self.ob.matrix_world.copy()
        matz = Matrix()
        matz[2][2] = -1
        self.xforms += [mat * matz]

    def export(self, render_engine, w):
        render_engine.update_stats("", "Psychopath: Exporting %s" % self.ob.name)
        w.write("Camera {\n")
        w.indent()

        for fov in self.fovs:
            w.write("Fov [%f]\n" % fov)

        for rad in self.aperture_radii:
            w.write("ApertureRadius [%f]\n" % rad)

        for dist in self.focal_distances:
            w.write("FocalDistance [%f]\n" % dist)

        for mat in self.xforms:

            w.write("Transform [%s]\n" % mat2str(mat))