forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture2DArray.py
More file actions
84 lines (74 loc) · 2.59 KB
/
Texture2DArray.py
File metadata and controls
84 lines (74 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from typing import Optional, List
from .Texture import Texture
from .Texture2D import StreamingInfo
from ..enums.GraphicsFormat import GraphicsFormat, GRAPHICS_TO_TEXTURE_MAP
from ..export import Texture2DConverter
from ..helpers.ResourceReader import get_resource_data
from PIL import Image
class GLTextureSettings:
m_Aniso: int
m_FilterMode: int
m_MipBias: float
m_WrapMode: Optional[int] = None
m_WrapU: Optional[int] = None
m_WrapV: Optional[int] = None
m_WrapW: Optional[int] = None
def __init__(self, reader):
self.__dict__.update(**self.read_typetree(wrap=True).__dict__)
class Texture2DArray(Texture):
image_data: bytes
m_ColorSpace: int
m_DataSize: int
m_Depth: int
m_Format: GraphicsFormat
m_Height: int
m_IsReadable: bool
m_MipCount: int
m_Name: str
m_TextureSettings: GLTextureSettings
m_Width: int
m_DownscaleFallback: Optional[bool] = None
m_ForcedFallbackFormat: Optional[int] = None
m_IgnoreMipmapLimit: Optional[bool] = None
m_IsAlphaChannelOptional: Optional[bool] = None
m_MipmapLimitGroupName: Optional[str] = None
m_MipsStripped: Optional[int] = None
m_StreamData: Optional[StreamingInfo] = None
m_UsageMode: Optional[int] = None
def __init__(self, reader):
super().__init__(reader=reader)
self.__dict__.update(**reader.read_typetree(wrap=True).__dict__)
self.m_TextureSettings.__class__ = GLTextureSettings
self.m_Format = GraphicsFormat(self.m_Format)
@property
def image_data(self):
data = getattr(self, "image data", None)
if data is None:
data = get_resource_data(
self.m_StreamData.path,
self.assets_file,
self.m_StreamData.offset,
self.m_StreamData.size,
)
return data
@property
def images(self) -> List[Image.Image]:
texture_format = GRAPHICS_TO_TEXTURE_MAP.get(self.m_Format)
if not texture_format:
raise NotImplementedError(
f"GraphicsFormat {self.m_Format} not supported yet"
)
# calculate the number of textures in the array
texture_size = self.m_DataSize // self.m_Depth
return [
Texture2DConverter.parse_image_data(
self.image_data[offset : offset + texture_size],
self.m_Width,
self.m_Height,
texture_format,
self.version,
0,
None,
)
for offset in range(0, self.m_DataSize, texture_size)
]