-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
59 lines (47 loc) · 2.02 KB
/
utils.py
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
import time
import typing
import struct
import bpy
from .rat_types import (IGHeader, IGSectionChunk, SectionIDTypeEnum, ZoneSectionIDTypeEnum, TieSectionIDTypeEnum,
MobyIDTypeEnum, LevelNamesEnum)
from .stream_helper import StreamHelper
def read_ighw_header(stream: StreamHelper):
header: IGHeader = IGHeader()
header.magic1 = stream.readUInt(0x00)
header.magic2 = stream.readUInt(0x04)
header.chunks_count = stream.readUInt(0x08)
header.length = stream.readUInt(0x0C)
return header
def read_sections_chunks(headers: IGHeader, stream: StreamHelper, __relative_offset: int = 0):
stream.seek(__relative_offset + 0x20)
for i in range(headers.length // 0x10):
sectionChunk: IGSectionChunk = IGSectionChunk()
sectionChunk.id = stream.readUInt(0x00)
sectionChunk.offset = stream.readUInt(0x04)
sectionChunk.count = stream.readUInt(0x08)
sectionChunk.length = stream.readUInt(0x0C)
stream.jump(0x10)
yield sectionChunk
def query_section(chunks: list[IGSectionChunk], section_id: int):
if section_id in [chunk.id for chunk in chunks]:
for section in chunks:
if section.id == section_id:
return section
def find_cleanlvlname(level_name: str) -> str:
locallevelname = level_name.replace(' ', 'µ', -1)
lvl_collection: typing.Any
lvl_collec_pname: str
clean_lvlname: str
if locallevelname in LevelNamesEnum.__dict__:
clean_lvlname = LevelNamesEnum[locallevelname].value
else:
clean_lvlname = level_name.replace(' ', '_', -1)
return clean_lvlname
def create_image_from_buffer(buffer, width, height):
# Create a new image in Blender
image = bpy.data.images.new(name="Texture", width=width, height=height)
# Convert the buffer to a list of tuples containing RGBA values
rgba_values = struct.unpack(str(width * height * 4) + "B", buffer)
# Assign the RGBA values to the image
image.pixels = [channel / 255 for channel in rgba_values]
return image