Skip to content

Commit

Permalink
Ready to release. Unsymboled useless parts of the code.
Browse files Browse the repository at this point in the history
Optimized few things.

Reviewed-by: V E L Δ <36549174+veld-dev@users.noreply.github.com>
  • Loading branch information
VELD-Dev committed Feb 18, 2023
1 parent baf95d4 commit 8f48092
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .idea/BlendCharmSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os.path
import os
import sys
import typing

import bpy
Expand All @@ -33,7 +35,7 @@
"R&T Importer was made for animators, fangame developers and all those fan stuff. "
"R&T Importer IS NOT made for level editing ! Use Lunacy Level Editor instead."),
"blender": (3, 3, 0),
"version": (1, 0, 0),
"version": (1, 1, 0),
"location": "File > Import > Extract & Import RAC Assets",
"warning": "Work in progress, be careful, the mod may crash Blender, always backup your files !",
"doc_url": "https://github.com/VELD-Dev/raclette-and-tank",
Expand All @@ -50,15 +52,15 @@
importlib.reload(file_manager)
importlib.reload(assets_manager)
importlib.reload(mobys)
importlib.reload(types)
importlib.reload(rat_types)
importlib.reload(ties)
importlib.reload(zones)
importlib.reload(stream_helper)
importlib.reload(bmesh_manager)
else:
import file_manager
import assets_manager
import types
import rat_types
import bmesh_manager
import utils

Expand All @@ -80,7 +82,6 @@

def extract_and_import(operator, context):
dirname = operator.directory
print(dirname)
filemanager = file_manager.FileManager(dirname)
assetmanager = assets_manager.AssetManager(filemanager, operator)

Expand Down Expand Up @@ -126,7 +127,7 @@ def extract_and_import(operator, context):
normals.append(vertex.__nortuple__())
mesh.from_pydata(verts, [], faces)
mesh = bmesh_manager.mapUVs(mesh, uvs)
mesh = bmesh_manager.mapNormals(mesh, normals)
# mesh = bmesh_manager.set_normals(mesh, normals)
mesh.update()
submeshes.append(mesh)
ties[tie.tie.tie.tuid] = submeshes
Expand All @@ -141,9 +142,7 @@ def extract_and_import(operator, context):

zones = {}
for zone in assetmanager.zones:
print(zone)
zones[zone.zone_tuid] = zone
print(f"Zone {zone.zone_tuid} Class Inst: {zone.__dict__} - Ties: {len(zone.ties_instances)}")
for zone in zones.values():
for tie_inst in zone.ties_instances:
ties_data = assetmanager.ties
Expand Down
15 changes: 2 additions & 13 deletions assets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,47 @@
from . import textures
from . import file_manager
from .stream_helper import (StreamHelper)
from .types import (IGAssetRef, IGSectionChunk)
from .rat_types import (IGAssetRef, IGSectionChunk)
from .utils import (read_sections_chunks, read_ighw_header, query_section)


class AssetManager:
def __init__(self, fm: file_manager.FileManager, operator):
self.textures_ref: list[IGAssetRef] = list[IGAssetRef]()
print("AssetManager: INIT")
isOld = fm.isIE2
self.fm: file_manager.FileManager = fm
self.mobys_refs: list[IGAssetRef] = list[IGAssetRef]()
self.ties_refs: list[IGAssetRef] = list[IGAssetRef]()
self.zones_refs: list[IGAssetRef] = list[IGAssetRef]()
self.ties_instances: list[zones.CTieInstance] = list[zones.CTieInstance]()
if isOld is False:
print("AssetManager: Is Not Old!")
print(fm.igfiles)
for idx, igfile in enumerate(fm.igfiles):
stream = fm.igfiles[igfile]
stream.seek(0x00)
headers = read_ighw_header(stream)
print("----\nIGFILE {0}: {1}".format(igfile, headers.__dict__))
if igfile == "assetlookup.dat":
sections_chunks = read_sections_chunks(headers, stream)
self.sections: list[IGSectionChunk] = list[IGSectionChunk]()
for section_chunk in sections_chunks:
self.sections.append(section_chunk)
print("o:{2} IGCHNK {0}: {1}".format(hex(section_chunk.id), section_chunk, stream.offset))

for idx, igfile in enumerate(fm.otherfiles):
stream = fm.otherfiles[igfile]
headers = read_ighw_header(stream)
print("----\nAM-OTHER_IGFILE {0}: {1}".format(igfile, headers.__dict__))
if igfile == "ties.dat" and operator.use_ties:
self.LoadTies()
self.ties = dict()
for tie_ref in self.ties_refs:
# print("----")
tie = ties.TieRefReader(stream, tie_ref)
self.ties[tie.tie.tie.tuid] = tie
elif igfile == "zones.dat" and operator.use_zones:
self.LoadZones()
self.zones = list[zones.ZoneReader]()
for zone_ref in self.zones_refs:
print("----")
print(zone_ref.__dict__)
zone = zones.ZoneReader(stream, zone_ref)
if zone.ties_instances is not None:
self.zones.append(zone)
#elif igfile == "highmips.dat" and operator.use_textures:
# elif igfile == "highmips.dat" and operator.use_textures:
# self.LoadTextures()
# self.textures = list[textures.TextureReader]()
# for texture_ref in self.textures_ref:
Expand Down Expand Up @@ -116,7 +107,6 @@ def LoadTexturesNew(self):
assetlookup.jump(0x10)
self.textures_ref.append(asset_ref)


###############
#### ZONES ####
###############
Expand All @@ -140,7 +130,6 @@ def LoadZonesNew(self):
asset_ref.tuid = assetlookup.readULong(0x00)
asset_ref.offset = assetlookup.readUInt(0x08)
asset_ref.length = assetlookup.readUInt(0x0C)
print(f"o:{hex(assetlookup.offset)} ZONE_RAW-REF {hex(asset_ref.tuid)}: {asset_ref.__dict__}")
assetlookup.jump(0x10)
self.zones_refs.append(asset_ref)

Expand Down
19 changes: 5 additions & 14 deletions bmesh_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ def mapUVs(mesh, uvs):
return mesh


def mapNormals(mesh, normals):
def set_normals(mesh, normals):
bm = bmesh.new()
bm.from_mesh(mesh)
bm.verts.ensure_lookup_table()
bm.edges.ensure_lookup_table()
bm.faces.ensure_lookup_table()

verts = bm.verts
for i in range(len(verts)):
normal = normals[i]
verts[i].normal = normal
for i, poly in enumerate(bm.faces):
poly.normal_update()
poly.normal = normals[i]

bm.to_mesh(mesh)
bm.free()
return mesh


Expand All @@ -52,21 +49,15 @@ def clone(mesh):


def center_origin_to_geometry(obj):
# Obtient la référence au mesh de l'objet
mesh = obj.data
bm = bmesh.new()
bm.from_mesh(mesh)
# Calcule le centre de masse du mesh
center_of_mass = mathutils.Vector()
for v in bm.verts:
center_of_mass += v.co
center_of_mass /= len(bm.verts)
# Calcule le vecteur de translation pour déplacer les sommets du mesh
translate_vec = -center_of_mass
# Déplace les sommets du mesh avec le vecteur de translation
bmesh.ops.translate(bm, vec=translate_vec, verts=bm.verts)
# Déplace l'origine de l'objet vers le centre de masse du mesh
obj.location += center_of_mass
# Met à jour le mesh à partir du BMesh
bm.to_mesh(mesh)
bm.free()
6 changes: 3 additions & 3 deletions debug.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from . import stream_helper
from . import types
from . import rat_types
from .utils import (read_sections_chunks, read_ighw_header, query_section)


class Debug:
stream: stream_helper.StreamHelper
header: types.IGHeader
chunks: list[types.IGSectionChunk]
header: rat_types.IGHeader
chunks: list[rat_types.IGSectionChunk]

def __init__(self, stream: stream_helper.StreamHelper):
self.stream = stream
Expand Down
1 change: 0 additions & 1 deletion file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class FileManager:

def __init__(self, folderpath: str):
print("FileManager: INIT")
self.folderpath = folderpath
self.igfiles: dict[str, StreamHelper] = dict[str, StreamHelper]()
self.otherfiles: dict[str, StreamHelper] = dict[str, StreamHelper]()
Expand Down
File renamed without changes.
20 changes: 16 additions & 4 deletions textures.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
from . import types
from . import rat_types
from .stream_helper import (StreamHelper)
from . import utils
import io
from .libs.imageio import v2 as imageio

def convert_dxt_to_png(dxt_buffer):
# Charge l'image DXT à partir du buffer
img = imageio.imread(dxt_buffer, 'dds')

# Convertit l'image en PNG
png_buffer = io.BytesIO()
imageio.imwrite(png_buffer, img, format='png')
png_buffer.seek(0)

# Retourne le buffer de l'image PNG
return png_buffer.getvalue()
class TextureReader:
def __init__(self, stream: StreamHelper, texture_ref: types.IGAssetRef):
def __init__(self, stream: StreamHelper, texture_ref: rat_types.IGAssetRef):
stream.seek(texture_ref.offset)
self.ighw_header: types.IGHeader = utils.read_ighw_header(stream)
self.ighw_header: rat_types.IGHeader = utils.read_ighw_header(stream)
stream.jump(0x20)
self.ighw_chunks: list[types.IGSectionChunk] = list(utils.read_sections_chunks(self.ighw_header, stream))
self.ighw_chunks: list[rat_types.IGSectionChunk] = list(utils.read_sections_chunks(self.ighw_header, stream))

### READ TEXTURE METADATAS ###
Loading

0 comments on commit 8f48092

Please sign in to comment.