# Path: korman/exporter/mesh.py
# class _MeshManager:
#     def __init__(self, report=None):
#         self.context_stack = ExitStack()
#         if report is not None:
#             self._report = report
#         self._entered = False
#         self._overrides = {}
# 
#     @staticmethod
#     def add_progress_presteps(report):
#         report.progress_add_step("Applying Blender Mods")
# 
#     def _build_prop_dict(self, bstruct):
#         props = {}
#         for i in bstruct.bl_rna.properties:
#             ident = i.identifier
#             if ident == "rna_type":
#                 continue
#             props[ident] = getattr(bstruct, ident) if getattr(i, "array_length", 0) == 0 else tuple(getattr(bstruct, ident))
#         return props
# 
#     def __enter__(self):
#         assert self._entered is False, "_MeshManager is not reentrant"
#         self._entered = True
# 
#         self.context_stack.__enter__()
# 
#         scene = bpy.context.scene
#         self._report.progress_advance()
#         self._report.progress_range = len(scene.objects)
# 
#         # Some modifiers like "Array" will procedurally generate new geometry that will impact
#         # lightmap generation. The Blender Internal renderer does not seem to be smart enough to
#         # take this into account. Thus, we temporarily apply modifiers to ALL meshes (even ones that
#         # are not exported) such that we can generate proper lighting.
#         mesh_type = bpy.types.Mesh
#         for i in scene.objects:
#             if isinstance(i.data, mesh_type) and i.is_modified(scene, "RENDER"):
#                 # Remember, storing actual pointers to the Blender objects can cause bad things to
#                 # happen because Blender's memory management SUCKS!
#                 self._overrides[i.name] = { "mesh": i.data.name, "modifiers": [] }
#                 i.data = i.to_mesh(scene, True, "RENDER", calc_tessface=False)
# 
#                 # If the modifiers are left on the object, the lightmap bake can break under some
#                 # situations. Therefore, we now cache the modifiers and clear them away...
#                 if i.plasma_object.enabled:
#                     cache_mods = self._overrides[i.name]["modifiers"]
#                     for mod in i.modifiers:
#                         cache_mods.append(self._build_prop_dict(mod))
#                     i.modifiers.clear()
#             self._report.progress_increment()
#         return self
# 
#     def __exit__(self, *exc_info):
#         try:
#             self.context_stack.__exit__(*exc_info)
#         finally:
#             data_bos, data_meshes = bpy.data.objects, bpy.data.meshes
#             for obj_name, override in self._overrides.items():
#                 bo = data_bos.get(obj_name)
# 
#                 # Reapply the old mesh
#                 trash_mesh, bo.data = bo.data, data_meshes.get(override["mesh"])
#                 data_meshes.remove(trash_mesh)
# 
#                 # If modifiers were removed, reapply them now unless they're read-only.
#                 readonly_attributes = {("DECIMATE", "face_count"),}
#                 for cached_mod in override["modifiers"]:
#                     mod = bo.modifiers.new(cached_mod["name"], cached_mod["type"])
#                     for key, value in cached_mod.items():
#                         if key in {"name", "type"} or (cached_mod["type"], key) in readonly_attributes:
#                             continue
#                         setattr(mod, key, value)
#             self._entered = False
# 
#     def is_collapsed(self, bo) -> bool:
#         return bo.name in self._overrides
# 
# _VERTEX_COLOR_LAYERS = {"col", "color", "colour"}


import bpy
import itertools
from contextlib import contextmanager
from .explosions import *
from .logger import ExportProgressLogger, ExportVerboseLogger
from .mesh import _MeshManager, _VERTEX_COLOR_LAYERS
from ..helpers import *
            self._own_report = False

        # This used to be the base class, but due to the need to access the export state
        # which may be stored in the exporter's mesh manager, we've changed from is-a to has-a
        # semantics. Sorry for this confusion!
        self._mesh = _MeshManager(self._report) if mesh is None else mesh

        self.vcol_layer_name = "autocolor"
        self.lightmap_name = "{}_LIGHTMAPGEN.png"
        self.lightmap_uvtex_name = "LIGHTMAPGEN"
        self.retain_lightmap_uvtex = True
        self.force = False
        self._lightmap_images = {}
        self._uvtexs = {}
        self._active_vcols = {}

    def __del__(self):
        if self._own_report:
            self._report.progress_end()

    def __enter__(self):
        self._mesh.__enter__()
        return self

    def __exit__(self, *exc_info):
        self._mesh.__exit__(*exc_info)

    @staticmethod
    def add_progress_steps(report, add_base=False):
        if add_base:

# Path: korman/exporter/mesh.py
# class _MeshManager:
#     def __init__(self, report=None):
#         self.context_stack = ExitStack()
#         if report is not None:
#             self._report = report
#         self._entered = False
#         self._overrides = {}
# 
#     @staticmethod
#     def add_progress_presteps(report):
#         report.progress_add_step("Applying Blender Mods")
# 
#     def _build_prop_dict(self, bstruct):
#         props = {}
#         for i in bstruct.bl_rna.properties:
#             ident = i.identifier
#             if ident == "rna_type":
#                 continue
#             props[ident] = getattr(bstruct, ident) if getattr(i, "array_length", 0) == 0 else tuple(getattr(bstruct, ident))
#         return props
# 
#     def __enter__(self):
#         assert self._entered is False, "_MeshManager is not reentrant"
#         self._entered = True
# 
#         self.context_stack.__enter__()
# 
#         scene = bpy.context.scene
#         self._report.progress_advance()
#         self._report.progress_range = len(scene.objects)
# 
#         # Some modifiers like "Array" will procedurally generate new geometry that will impact
#         # lightmap generation. The Blender Internal renderer does not seem to be smart enough to
#         # take this into account. Thus, we temporarily apply modifiers to ALL meshes (even ones that
#         # are not exported) such that we can generate proper lighting.
#         mesh_type = bpy.types.Mesh
#         for i in scene.objects:
#             if isinstance(i.data, mesh_type) and i.is_modified(scene, "RENDER"):
#                 # Remember, storing actual pointers to the Blender objects can cause bad things to
#                 # happen because Blender's memory management SUCKS!
#                 self._overrides[i.name] = { "mesh": i.data.name, "modifiers": [] }
#                 i.data = i.to_mesh(scene, True, "RENDER", calc_tessface=False)
# 
#                 # If the modifiers are left on the object, the lightmap bake can break under some
#                 # situations. Therefore, we now cache the modifiers and clear them away...
#                 if i.plasma_object.enabled:
#                     cache_mods = self._overrides[i.name]["modifiers"]
#                     for mod in i.modifiers:
#                         cache_mods.append(self._build_prop_dict(mod))
#                     i.modifiers.clear()
#             self._report.progress_increment()
#         return self
# 
#     def __exit__(self, *exc_info):
#         try:
#             self.context_stack.__exit__(*exc_info)
#         finally:
#             data_bos, data_meshes = bpy.data.objects, bpy.data.meshes
#             for obj_name, override in self._overrides.items():
#                 bo = data_bos.get(obj_name)
# 
#                 # Reapply the old mesh
#                 trash_mesh, bo.data = bo.data, data_meshes.get(override["mesh"])
#                 data_meshes.remove(trash_mesh)
# 
#                 # If modifiers were removed, reapply them now unless they're read-only.
#                 readonly_attributes = {("DECIMATE", "face_count"),}
#                 for cached_mod in override["modifiers"]:
#                     mod = bo.modifiers.new(cached_mod["name"], cached_mod["type"])
#                     for key, value in cached_mod.items():
#                         if key in {"name", "type"} or (cached_mod["type"], key) in readonly_attributes:
#                             continue
#                         setattr(mod, key, value)
#             self._entered = False
# 
#     def is_collapsed(self, bo) -> bool:
#         return bo.name in self._overrides
# 
# _VERTEX_COLOR_LAYERS = {"col", "color", "colour"}


# Path: korman/exporter/etlight.py
import bpy
import itertools
from contextlib import contextmanager
from .explosions import *
from .logger import ExportProgressLogger, ExportVerboseLogger
from .mesh import _MeshManager, _VERTEX_COLOR_LAYERS
from ..helpers import *

            self._own_report = False

        # This used to be the base class, but due to the need to access the export state
        # which may be stored in the exporter's mesh manager, we've changed from is-a to has-a
        # semantics. Sorry for this confusion!
        self._mesh = _MeshManager(self._report) if mesh is None else mesh

        self.vcol_layer_name = "autocolor"
        self.lightmap_name = "{}_LIGHTMAPGEN.png"
        self.lightmap_uvtex_name = "LIGHTMAPGEN"
        self.retain_lightmap_uvtex = True
        self.force = False
        self._lightmap_images = {}
        self._uvtexs = {}
        self._active_vcols = {}

    def __del__(self):
        if self._own_report:
            self._report.progress_end()

    def __enter__(self):
        self._mesh.__enter__()
        return self

    def __exit__(self, *exc_info):
        self._mesh.__exit__(*exc_info)

    @staticmethod
    def add_progress_steps(report, add_base=False):
        if add_base:

            _MeshManager.add_progress_presteps(report)