diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index 05e05dd..7dc9ae8 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -350,6 +350,10 @@ class Exporter: self.mgr.save_age(Path(self._op.filepath)) self.image.save() + @property + def envmap_method(self): + return bpy.context.scene.world.plasma_age.envmap_method + @property def texcache_path(self): age = bpy.context.scene.world.plasma_age diff --git a/korman/exporter/material.py b/korman/exporter/material.py index e85ec51..b2d680a 100644 --- a/korman/exporter/material.py +++ b/korman/exporter/material.py @@ -139,13 +139,41 @@ class MaterialConverter: "transformCtl": self._export_layer_transform_animation, } + def _can_export_texslot(self, slot): + if slot is None or not slot.use: + return False + texture = slot.texture + if texture is None or texture.type not in self._tex_exporters: + return False + + # Per-texture type rules + if texture.type == "ENVIRONMENT_MAP": + envmap = texture.environment_map + # If this is a static, image based cube map, then we will allow it + # to be exported anyway. Note that as of the writing of this code, + # that is kind of pointless because CEMs are not yet implemented... + if envmap.source == "IMAGE_FILE": + return True + + # Now for the ruelz + method, ver = self._exporter().envmap_method, self._mgr.getVer() + if method == "skip": + return False + elif method == "dcm2dem": + return True + elif method == "perengine": + return (ver >= pvMoul and envmap.mapping == "PLANE") or envmap.mapping == "CUBE" + else: + raise NotImplementedError(method) + else: + return True + def export_material(self, bo, bm): """Exports a Blender Material as an hsGMaterial""" self._report.msg("Exporting Material '{}'", bm.name, indent=1) hsgmat = self._mgr.add_object(hsGMaterial, name=bm.name, bl=bo) - slots = [(idx, slot) for idx, slot in enumerate(bm.texture_slots) if slot is not None and slot.use \ - and slot.texture is not None and slot.texture.type in self._tex_exporters] + slots = [(idx, slot) for idx, slot in enumerate(bm.texture_slots) if self._can_export_texslot(slot)] # There is a major difference in how Blender and Plasma handle stencils. # In Blender, the stencil is on top and applies to every layer below is. In Plasma, the stencil @@ -453,6 +481,8 @@ class MaterialConverter: texture = slot.texture bl_env = texture.environment_map if bl_env.source in {"STATIC", "ANIMATED"}: + # NOTE: It is assumed that if we arrive here, we are at lease dcm2dem on the + # environment map export method. You're welcome! if bl_env.mapping == "PLANE" and self._mgr.getVer() >= pvMoul: pl_env = plDynamicCamMap else: diff --git a/korman/operators/op_export.py b/korman/operators/op_export.py index d137410..a676420 100644 --- a/korman/operators/op_export.py +++ b/korman/operators/op_export.py @@ -64,6 +64,13 @@ class ExportOperator(bpy.types.Operator): ("force_lightmap", "Force Lightmap Bake", "All static lighting is baked as lightmaps (slower export)")], "default": "bake"}), + "envmap_method": (EnumProperty, {"name": "Environment Maps", + "description": "Environment Map Settings", + "items": [("skip", "Don't Export EnvMaps", "Environment Maps are not exported (the age runs faster)"), + ("dcm2dem", "Downgrade Planar EnvMaps", "When the engine doesn't support them, Planar Environment Maps are downgraded to Cube Maps"), + ("perengine", "Export Supported EnvMaps", "Only environment maps supported by the selected game engine are exported")], + "default": "dcm2dem"}), + "export_active": (BoolProperty, {"name": "INTERNAL: Export currently running", "default": False, "options": {"SKIP_SAVE"}}), diff --git a/korman/ui/ui_world.py b/korman/ui/ui_world.py index 1400280..c5580c4 100644 --- a/korman/ui/ui_world.py +++ b/korman/ui/ui_world.py @@ -143,6 +143,7 @@ class PlasmaAgePanel(AgeButtonsPanel, bpy.types.Panel): col.prop(age, "use_texture_page") layout.separator() + layout.prop(age, "envmap_method") layout.prop(age, "lighting_method") layout.prop(age, "texcache_method")