Skip to content

Commit

Permalink
Fix #407.
Browse files Browse the repository at this point in the history
As it turns out, these have been completely wrong since the beginning.
The disabled texture is, you guessed it, a texture--NOT a layer. Fix it.
  • Loading branch information
Hoikas committed Mar 3, 2024
1 parent e2bf2fa commit 106ef01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
22 changes: 13 additions & 9 deletions korman/exporter/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,19 @@ def export_dynamic_env(self, bo, layer, texture, pl_class):
pl_env.addTargetNode(self._mgr.find_key(plSceneObject, bl=bo))
pl_env.addMatLayer(layer.key)

# This is really just so we don't raise any eyebrows if anyone is looking at the files.
# If you're disabling DCMs, then you're obviuously trolling!
# Cyan generates a single color image, but we'll just set the layer colors and go away.
fake_layer = self._mgr.find_create_object(plLayer, bl=bo, name="{}_DisabledDynEnvMap".format(texture.name))
fake_layer.ambient = layer.ambient
fake_layer.preshade = layer.preshade
fake_layer.runtime = layer.runtime
fake_layer.specular = layer.specular
pl_env.disableTexture = fake_layer.key
# Generate a single color image for use as a disabled texture.
disabled_color = utils.color_to_argb(texture.plasma_layer.envmap_color)
mm_name = f"StaticColorTex_4x4_{disabled_color:08X}"
tex_loc = self._mgr.get_textures_page(pl_env.key)
color_mm = self._mgr.find_object(plMipmap, name=mm_name, loc=tex_loc)
if color_mm is None:
color_mm = plMipmap(
name=mm_name, width=4, height=4, numLevels=1,
compType=plBitmap.kUncompressed, format=plBitmap.kRGB8888
)
color_mm.setRawImage(int.to_bytes(disabled_color, 4, byteorder="little") * 16)
self._mgr.add_object(color_mm, loc=tex_loc)
pl_env.disableTexture = color_mm.key

if pl_env.camera is None:
layer.UVWSrc = plLayerInterface.kUVWPosition
Expand Down
8 changes: 8 additions & 0 deletions korman/exporter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def color(blcolor, alpha=1.0):
"""Converts a Blender Color into an hsColorRGBA"""
return hsColorRGBA(blcolor.r, blcolor.g, blcolor.b, alpha)

def color_to_argb(color, alpha=1.0):
return (
int(alpha * 255) << 24 |
int(color.r * 255) << 16 |
int(color.b * 255) << 8 |
int(color.g * 255)
) & 0xFFFFFFFF

def matrix44(blmat):
"""Converts a mathutils.Matrix to an hsMatrix44"""
hsmat = hsMatrix44()
Expand Down

0 comments on commit 106ef01

Please sign in to comment.