diff --git a/korman/exporter/material.py b/korman/exporter/material.py index 4b973e4..9bdc221 100644 --- a/korman/exporter/material.py +++ b/korman/exporter/material.py @@ -147,6 +147,16 @@ class MaterialConverter: "transformCtl": self._export_layer_transform_animation, } + def calc_material_ambient(self, bo, bm) -> hsColorRGBA: + emit_scale = bm.emit * 0.5 + if emit_scale > 0.0: + return hsColorRGBA(bm.diffuse_color.r * emit_scale, + bm.diffuse_color.g * emit_scale, + bm.diffuse_color.b * emit_scale, + 1.0) + else: + return utils.color(bpy.context.scene.world.ambient_color) + def _can_export_texslot(self, slot): if slot is None or not slot.use: return False @@ -187,7 +197,9 @@ class MaterialConverter: self._report.msg("Exporting Material '{}' as single user '{}'", bm.name, mat_name, indent=1) hgmat = None else: - mat_name = bm.name + # Ensure that RT-lit objects don't infect the static-lit objects. + mat_prefix = "RTLit_" if bo.plasma_modifiers.lighting.rt_lights else "" + mat_name = "".join((mat_prefix, bm.name)) self._report.msg("Exporting Material '{}'", mat_name, indent=1) hsgmat = self._mgr.find_key(hsGMaterial, name=mat_name, bl=bo) if hsgmat is not None: @@ -222,7 +234,8 @@ class MaterialConverter: if slot.use_stencil: stencils.append((idx, slot)) else: - tex_layer = self.export_texture_slot(bo, bm, hsgmat, slot, idx) + tex_name = "{}_{}".format(mat_name, slot.name) + tex_layer = self.export_texture_slot(bo, bm, hsgmat, slot, idx, name=tex_name) if restart_pass_next: tex_layer.state.miscFlags |= hsGMatState.kMiscRestartPassHere restart_pass_next = False @@ -249,7 +262,7 @@ class MaterialConverter: # Plasma makes several assumptions that every hsGMaterial has at least one layer. If this # material had no Textures, we will need to initialize a default layer if not hsgmat.layers: - layer = self._mgr.find_create_object(plLayer, name="{}_AutoLayer".format(bm.name), bl=bo) + layer = self._mgr.find_create_object(plLayer, name="{}_AutoLayer".format(mat_name), bl=bo) self._propagate_material_settings(bo, bm, layer) hsgmat.addLayer(layer.key) @@ -349,7 +362,7 @@ class MaterialConverter: return hsgmat.key def export_bumpmap_slot(self, bo, bm, hsgmat, slot, idx): - name = "{}_{}".format(bm.name if bm is not None else bo.name, slot.name) + name = "{}_{}".format(hsgmat.key.name, slot.name) self._report.msg("Exporting Plasma Bumpmap Layers for '{}'", name, indent=2) # Okay, now we need to make 3 layers for the Du, Dw, and Dv @@ -1163,6 +1176,20 @@ class MaterialConverter: def get_bump_layer(self, bo): return self._bump_mats.get(bo, None) + def get_material_preshade(self, bo, bm, color=None) -> hsColorRGBA: + if bo.plasma_modifiers.lighting.rt_lights or bm.emit: + return hsColorRGBA.kBlack + if color is None: + color = bm.diffuse_color + return utils.color(color) + + def get_material_runtime(self, bo, bm, color=None) -> hsColorRGBA: + if bm.emit: + return hsColorRGBA.kBlack + if color is None: + color = bm.diffuse_color + return utils.color(color) + def get_texture_animation_key(self, bo, bm, texture): """Finds or creates the appropriate key for sending messages to an animated Texture""" @@ -1204,23 +1231,17 @@ class MaterialConverter: if bm.use_shadeless: state.shadeFlags |= hsGMatState.kShadeWhite + if bm.emit: + state.shadeFlags |= hsGMatState.kShadeEmissive + # Colors - layer.ambient = utils.color(bpy.context.scene.world.ambient_color) - layer.preshade = utils.color(bm.diffuse_color) - layer.runtime = utils.color(bm.diffuse_color) + layer.ambient = self.calc_material_ambient(bo, bm) + layer.preshade = self.get_material_preshade(bo, bm) + layer.runtime = self.get_material_runtime(bo, bm) layer.specular = utils.color(bm.specular_color) layer.specularPower = min(100.0, float(bm.specular_hardness)) - layer.LODBias = -1.0 # Seems to be the Plasma default - - if bm.emit > 0.0: - # Use the diffuse colour as the emit, scaled by the emit amount - # (maximum 2.0, so we'll also scale that by 0.5) - emit_scale = bm.emit * 0.5 - layer.ambient = hsColorRGBA(bm.diffuse_color.r * emit_scale, - bm.diffuse_color.g * emit_scale, - bm.diffuse_color.b * emit_scale, - 1.0) + layer.LODBias = -1.0 def _requires_single_user(self, bo, bm): if bo.data.show_double_sided: diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index 491af68..1f1dc7d 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -279,7 +279,7 @@ class MeshConverter(_MeshManager): # TODO: if this is an avatar, we can't be non-preshaded. if check_layer_shading_animation(base_layer): return False - if base_layer.state.shadeFlags & hsGMatState.kShadeEmissive: + if material_idx is not None and mesh.materials[material_idx].emit: return False mods = bo.plasma_modifiers