From 9b1787c16266314b453c4129b51d0f6f76ba8021 Mon Sep 17 00:00:00 2001 From: red031000 Date: Mon, 11 Nov 2024 20:55:32 +0200 Subject: [PATCH] command 0x2A: TexImageParam --- g3_commands.py | 44 +++++++++++++++++++++++++++++++++++++++- import_nsbmd.py | 54 +------------------------------------------------ utils.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 54 deletions(-) diff --git a/g3_commands.py b/g3_commands.py index 8de7af2..bfcc23d 100644 --- a/g3_commands.py +++ b/g3_commands.py @@ -1,4 +1,4 @@ -from .utils import error, read32, np_fixed_to_float, fixed_to_float, to_rgb, vec10_to_vec, PolygonMode, CullMode +from .utils import error, read32, np_fixed_to_float, fixed_to_float, to_rgb, vec10_to_vec, PolygonMode, CullMode, TexturePalette0Mode, TextureFlip, TextureRepeat, TextureTSize, TextureSSize, TextureConversionMode, TextureFormat from enum import IntEnum import numpy as np @@ -137,6 +137,12 @@ def parse_dl_command(data, offset, commandData, report_func): polyAttr = DLCommandPolygonAttr() polyAttr.parse(attributes) commands.append(polyAttr) + elif command == 0x2A: + attributes = read32(data, offset) + offset += 4 + texImageParam = DLCommandTexImageParam() + texImageParam.parse(attributes) + commands.append(texImageParam) #todo more commands return commands, offset @@ -305,3 +311,39 @@ class DLCommandPolygonAttr(DLCommand): self.depthTest = (attributes >> 14) & 0x1 != 0 self.fog = (attributes >> 15) & 0x1 != 0 + +class DLCommandTexImageParam(DLCommand): + def __init__(self): + super().__init__(0x2A) + self.texturePalette0Mode = TexturePalette0Mode.USE + self.textureFlip = TextureFlip.NONE + self.textureRepeat = TextureRepeat.NONE + self.textureTSize = TextureTSize.T8 + self.textureSSize = TextureSSize.S8 + self.textureConversionMode = TextureConversionMode.NONE + self.textureFormat = TextureFormat.NONE + self.textureAddress = 0 + + def parse(self, attributes): + texturePalette0Mode = (attributes >> 29) & 0x1 + self.texturePalette0Mode = TexturePalette0Mode(texturePalette0Mode) + + textureFlip = (attributes >> 18) & 0x3 + self.textureFlip = TextureFlip(textureFlip) + + textureRepeat = (attributes >> 16) & 0x3 + self.textureRepeat = TextureRepeat(textureRepeat) + + textureTSize = (attributes >> 23) & 0x7 + self.textureTSize = TextureTSize(textureTSize) + + textureSSize = (attributes >> 20) & 0x7 + self.textureSSize = TextureSSize(textureSSize) + + textureConversionMode = (attributes >> 30) & 0x3 + self.textureConversionMode = TextureConversionMode(textureConversionMode) + + textureFormat = (attributes >> 26) & 0x7 + self.textureFormat = TextureFormat(textureFormat) + + self.textureAddress = attributes & 0xFFFF diff --git a/import_nsbmd.py b/import_nsbmd.py index a409be5..c9cd37c 100644 --- a/import_nsbmd.py +++ b/import_nsbmd.py @@ -1,6 +1,6 @@ from enum import IntEnum, IntFlag from os.path import isfile -from .utils import read8, read16, read32, read_str, log, debug, parse_dictionary, fixed_to_float, to_rgb, PolygonMode, CullMode +from .utils import read8, read16, read32, read_str, log, debug, parse_dictionary, fixed_to_float, to_rgb, PolygonMode, CullMode, TexturePalette0Mode, TextureFlip, TextureRepeat, TextureTSize, TextureSSize, TextureConversionMode, TextureFormat from .g3_commands import parse_dl import numpy as np @@ -198,58 +198,6 @@ class NSBMDMaterialPolygonAttributes(): self.fog = (attributes >> 15) & 0x1 != 0 log('Fog: %s' % self.fog, report_func) -class TextureFormat(IntEnum): - NONE = 0 - A3I5 = 1 - PLTT4 = 2 - PLTT16 = 3 - PLTT256 = 4 - COMP4X4 = 5 - A5I3 = 6 - DIRECT = 7 - -class TextureConversionMode(IntEnum): - NONE = 0 - TEXCOORD = 1 - NORMAL = 2 - VERTEX = 3 - -class TextureSSize(IntEnum): - S8 = 0 - S16 = 1 - S32 = 2 - S64 = 3 - S128 = 4 - S256 = 5 - S512 = 6 - S1024 = 7 - -class TextureTSize(IntEnum): - T8 = 0 - T16 = 1 - T32 = 2 - T64 = 3 - T128 = 4 - T256 = 5 - T512 = 6 - T1024 = 7 - -class TextureRepeat(IntEnum): - NONE = 0 - S = 1 - T = 2 - ST = 3 - -class TextureFlip(IntEnum): - NONE = 0 - S = 1 - T = 2 - ST = 3 - -class TexturePalette0Mode(IntEnum): - USE = 0 - TRANSPARENT = 1 - class NSBMDMaterialTextureImageParameters(): def __init__(self): self.address = 0 diff --git a/utils.py b/utils.py index 8971403..268299e 100644 --- a/utils.py +++ b/utils.py @@ -77,3 +77,55 @@ class CullMode(IntEnum): FRONT = 1 BACK = 2 BOTH = 3 + +class TexturePalette0Mode(IntEnum): + USE = 0 + TRANSPARENT = 1 + +class TextureFlip(IntEnum): + NONE = 0 + S = 1 + T = 2 + ST = 3 + +class TextureRepeat(IntEnum): + NONE = 0 + S = 1 + T = 2 + ST = 3 + +class TextureTSize(IntEnum): + T8 = 0 + T16 = 1 + T32 = 2 + T64 = 3 + T128 = 4 + T256 = 5 + T512 = 6 + T1024 = 7 + +class TextureSSize(IntEnum): + S8 = 0 + S16 = 1 + S32 = 2 + S64 = 3 + S128 = 4 + S256 = 5 + S512 = 6 + S1024 = 7 + +class TextureConversionMode(IntEnum): + NONE = 0 + TEXCOORD = 1 + NORMAL = 2 + VERTEX = 3 + +class TextureFormat(IntEnum): + NONE = 0 + A3I5 = 1 + PLTT4 = 2 + PLTT16 = 3 + PLTT256 = 4 + COMP4X4 = 5 + A5I3 = 6 + DIRECT = 7