2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 13:44:56 +00:00

Fixes for GameCube targeting

This commit is contained in:
Jack Andersen
2018-03-27 22:06:34 -10:00
parent d1a66e15d4
commit c9f61eb9da
16 changed files with 148 additions and 56 deletions

View File

@@ -273,7 +273,7 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
recursive_cook(buffer, ch, version, path_hasher, obj.name)
def cook(path_out, version, path_hasher):
def cook(writepipebuf, version, path_hasher):
global hjustifications, vjustifications, model_draw_flags_e
hjustifications = dict((i[0], i[3]) for i in bpy.types.Object.retro_textpane_hjustification[1]['items'])
vjustifications = dict((i[0], i[3]) for i in bpy.types.Object.retro_textpane_vjustification[1]['items'])
@@ -292,12 +292,7 @@ def cook(path_out, version, path_hasher):
if obj.retro_widget_type != 'RETRO_NONE' and not obj.parent:
recursive_cook(buffer, obj, version, path_hasher, 'kGSYS_DummyWidgetID')
rem_bytes = 32 - len(buffer) % 32
for i in range(rem_bytes):
buffer.append(0xff)
fout = open(path_out, 'wb')
fout.write(buffer)
fout.close()
return buffer
# Registration

View File

@@ -5,17 +5,20 @@ from mathutils import Vector
class VertPool:
# Initialize hash-unique index for each available attribute
def __init__(self, bm, rna_loops):
def __init__(self, bm, rna_loops, use_luv, material_slots):
self.bm = bm
self.rna_loops = rna_loops
self.material_slots = material_slots
self.pos = {}
self.norm = {}
self.skin = {}
self.color = {}
self.uv = {}
self.luv = {}
self.dlay = None
self.clays = []
self.ulays = []
self.luvlay = None
dlay = None
if len(bm.verts.layers.deform):
@@ -27,6 +30,10 @@ class VertPool:
clays.append(bm.loops.layers.color[cl])
self.clays = clays
luvlay = None
if use_luv:
luvlay = bm.loops.layers.uv[0]
self.luvlay = luvlay
ulays = []
for ul in range(len(bm.loops.layers.uv)):
ulays.append(bm.loops.layers.uv[ul])
@@ -48,6 +55,7 @@ class VertPool:
# Per-loop pool attributes
for f in bm.faces:
lightmapped = material_slots[f.material_index].material['retro_lightmapped']
for l in f.loops:
if rna_loops:
nf = rna_loops[l.index].normal.copy().freeze()
@@ -57,7 +65,13 @@ class VertPool:
cf = l[clays[cl]].copy().freeze()
if cf not in self.color:
self.color[cf] = len(self.color)
for ul in range(len(ulays)):
start_uvlay = 0
if use_luv and lightmapped:
start_uvlay = 1
uf = l[luvlay].uv.copy().freeze()
if uf not in self.luv:
self.luv[uf] = len(self.luv)
for ul in range(start_uvlay, len(ulays)):
uf = l[ulays[ul]].uv.copy().freeze()
if uf not in self.uv:
self.uv[uf] = len(self.uv)
@@ -79,6 +93,13 @@ class VertPool:
for u in sorted(self.uv.items(), key=operator.itemgetter(1)):
writebuf(struct.pack('ff', u[0][0], u[0][1]))
luv_count = 0
if self.luvlay is not None:
luv_count = 1
writebuf(struct.pack('II', luv_count, len(self.luv)))
for u in sorted(self.luv.items(), key=operator.itemgetter(1)):
writebuf(struct.pack('ff', u[0][0], u[0][1]))
writebuf(struct.pack('I', len(vert_groups)))
for vgrp in vert_groups:
writebuf(struct.pack('I', len(vgrp.name)))
@@ -122,6 +143,10 @@ class VertPool:
return self.color[cf]
def get_uv_idx(self, loop, uidx):
if self.luvlay is not None and uidx == 0:
if self.material_slots[loop.face.material_index].material['retro_lightmapped']:
uf = loop[self.luvlay].uv.copy().freeze()
return self.luv[uf]
uf = loop[self.ulays[uidx]].uv.copy().freeze()
return self.uv[uf]

View File

@@ -18,7 +18,6 @@ def write_out_material(writebuf, mat, mesh_obj):
if isinstance(prop[1], int):
prop_count += 1
writebuf(struct.pack('I', prop_count))
prop_count = 0
for prop in mat.items():
if isinstance(prop[1], int):
writebuf(struct.pack('I', len(prop[0])))
@@ -34,7 +33,7 @@ def write_out_material(writebuf, mat, mesh_obj):
# Takes a Blender 'Mesh' object (not the datablock)
# and performs a one-shot conversion process to HMDL
def cook(writebuf, mesh_obj, output_mode, max_skin_banks, max_octant_length=None):
def cook(writebuf, mesh_obj, output_mode, max_skin_banks, use_luv=False):
if mesh_obj.type != 'MESH':
raise RuntimeError("%s is not a mesh" % mesh_obj.name)
@@ -75,10 +74,9 @@ def cook(writebuf, mesh_obj, output_mode, max_skin_banks, max_octant_length=None
# Create master BMesh and VertPool
bm_master = bmesh.new()
bm_master.from_mesh(copy_mesh)
vert_pool = HMDLMesh.VertPool(bm_master, rna_loops)
vert_pool = HMDLMesh.VertPool(bm_master, rna_loops, use_luv, mesh_obj.material_slots)
# Tag edges where there are distinctive loops
splittable_edges = []
for e in bm_master.edges:
e.tag = vert_pool.splitable_edge(e)

View File

@@ -53,7 +53,7 @@ def cook(writebuf, mesh_obj):
# Create master BMesh and VertPool
bm_master = bmesh.new()
bm_master.from_mesh(copy_obj.data)
vert_pool = VertPool(bm_master, rna_loops)
vert_pool = VertPool(bm_master, rna_loops, False, mesh_obj.material_slots)
# Output vert pool
vert_pool.write_out_map(writebuf)

View File

@@ -217,13 +217,14 @@ def dataout_loop():
elif cmdargs[0] == 'MESHCOMPILENAME':
meshName = cmdargs[1]
maxSkinBanks = int(cmdargs[3])
useLuv = int(cmdargs[4])
if meshName not in bpy.data.objects:
writepipestr(('mesh %s not found' % meshName).encode())
continue
writepipestr(b'OK')
hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName], cmdargs[2], maxSkinBanks)
hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName], cmdargs[2], maxSkinBanks, useLuv)
elif cmdargs[0] == 'MESHCOMPILENAMECOLLISION':
meshName = cmdargs[1]
@@ -281,15 +282,16 @@ def dataout_loop():
hecl.swld.cook(writepipebuf)
elif cmdargs[0] == 'FRAMECOMPILE':
pathOut = cmdargs[1]
version = int(cmdargs[2])
version = int(cmdargs[1])
if version != 0 and version != 1:
writepipestr(b'bad version')
continue
writepipestr(b'OK')
hecl.frme.cook(pathOut, version, PathHasher())
buffer = hecl.frme.cook(writepipebuf, version, PathHasher())
writepipestr(b'FRAMEDONE')
writepipebuf(struct.pack('I', len(buffer)))
writepipebuf(buffer)
elif cmdargs[0] == 'LIGHTCOMPILEALL':
writepipestr(b'OK')