mirror of
https://github.com/red031000/nitrog3d.git
synced 2025-06-18 13:15:35 -04:00
polygon attr command
This commit is contained in:
parent
5f9ebe1065
commit
6e3a3e9011
@ -1,4 +1,4 @@
|
||||
from .utils import error, read32, np_fixed_to_float, fixed_to_float, to_rgb, vec10_to_vec
|
||||
from .utils import error, read32, np_fixed_to_float, fixed_to_float, to_rgb, vec10_to_vec, PolygonMode, CullMode
|
||||
from enum import IntEnum
|
||||
import numpy as np
|
||||
|
||||
@ -131,6 +131,12 @@ def parse_dl_command(data, offset, commandData, report_func):
|
||||
vertex = vec10_to_vec(read32(data, offset))
|
||||
offset += 4
|
||||
commands.append(DLCommandVtxDiff(vertex))
|
||||
elif command == 0x29:
|
||||
attributes = read32(data, offset)
|
||||
offset += 4
|
||||
polyAttr = DLCommandPolygonAttr()
|
||||
polyAttr.parse(attributes)
|
||||
commands.append(polyAttr)
|
||||
#todo more commands
|
||||
return commands, offset
|
||||
|
||||
@ -255,4 +261,47 @@ class DLCommandVtxYZ(DLCommand):
|
||||
class DLCommandVtxDiff(DLCommand):
|
||||
def __init__(self, vertex):
|
||||
super().__init__(0x28)
|
||||
self.vertex = vertex
|
||||
self.vertex = vertex
|
||||
|
||||
class DLCommandPolygonAttr(DLCommand):
|
||||
def __init__(self):
|
||||
super().__init__(0x29)
|
||||
self.lights = [False, False, False, False]
|
||||
self.polyMode = PolygonMode.MODULATE
|
||||
self.cullMode = CullMode.NONE
|
||||
self.polygonId = 0
|
||||
self.alpha = 0
|
||||
self.xluDepthUpdate = False
|
||||
self.farClipping = False
|
||||
self.display1Dot = False
|
||||
self.depthTest = False
|
||||
self.fog = False
|
||||
|
||||
def parse(self, attributes):
|
||||
light = attributes & 0xF
|
||||
self.lights[0] = (light & 0x1) != 0
|
||||
self.lights[1] = (light & 0x2) != 0
|
||||
self.lights[2] = (light & 0x4) != 0
|
||||
self.lights[3] = (light & 0x8) != 0
|
||||
|
||||
polyMode = (attributes >> 4) & 0x3
|
||||
self.polyMode = PolygonMode(polyMode)
|
||||
|
||||
cullMode = (attributes >> 6) & 0x3
|
||||
self.cullMode = CullMode(cullMode)
|
||||
|
||||
polygonId = (attributes >> 24) & 0x3F
|
||||
self.polygonId = polygonId
|
||||
|
||||
alpha = (attributes >> 16) & 0x1F
|
||||
self.alpha = alpha
|
||||
|
||||
self.xluDepthUpdate = (attributes >> 11) & 0x1 != 0
|
||||
|
||||
self.farClipping = (attributes >> 12) & 0x1 != 0
|
||||
|
||||
self.display1Dot = (attributes >> 13) & 0x1 != 0
|
||||
|
||||
self.depthTest = (attributes >> 14) & 0x1 != 0
|
||||
|
||||
self.fog = (attributes >> 15) & 0x1 != 0
|
||||
|
@ -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
|
||||
from .utils import read8, read16, read32, read_str, log, debug, parse_dictionary, fixed_to_float, to_rgb, PolygonMode, CullMode
|
||||
from .g3_commands import parse_dl
|
||||
import numpy as np
|
||||
|
||||
@ -145,18 +145,6 @@ class NSBMDTextureMaterialData():
|
||||
self.materialId = material_id
|
||||
self.bound = bound
|
||||
|
||||
class PolygonMode(IntEnum):
|
||||
MODULATE = 0
|
||||
DECAL = 1
|
||||
TOON = 2
|
||||
SHADOW = 3
|
||||
|
||||
class CullMode(IntEnum):
|
||||
NONE = 0
|
||||
FRONT = 1
|
||||
BACK = 2
|
||||
BOTH = 3
|
||||
|
||||
class NSBMDMaterialPolygonAttributes():
|
||||
def __init__(self):
|
||||
self.lights = [False, False, False, False]
|
||||
|
15
utils.py
15
utils.py
@ -1,3 +1,4 @@
|
||||
from enum import IntEnum
|
||||
import numpy as np
|
||||
|
||||
def read8(data, offset):
|
||||
@ -63,4 +64,16 @@ def np_fixed_to_float(value):
|
||||
return (value / 4096.0).astype('float')
|
||||
|
||||
def vec10_to_vec(value):
|
||||
return np_fixed_to_float(np.array([value & 0x3FF, (value >> 10) & 0x3FF, (value >> 20) & 0x3FF]))
|
||||
return np_fixed_to_float(np.array([value & 0x3FF, (value >> 10) & 0x3FF, (value >> 20) & 0x3FF]))
|
||||
|
||||
class PolygonMode(IntEnum):
|
||||
MODULATE = 0
|
||||
DECAL = 1
|
||||
TOON = 2
|
||||
SHADOW = 3
|
||||
|
||||
class CullMode(IntEnum):
|
||||
NONE = 0
|
||||
FRONT = 1
|
||||
BACK = 2
|
||||
BOTH = 3
|
||||
|
Loading…
Reference in New Issue
Block a user