1
0

refactor: change repo layout

This commit is contained in:
2026-01-24 19:46:23 +08:00
parent 34de35dd31
commit c2dafab217
82 changed files with 0 additions and 170 deletions

4
Assets/Debuggers/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore test used 3d Object
*.bin
*.obj
*.mtl

View File

@@ -0,0 +1,92 @@
import argparse, io, math, struct
# setup parser
parser = argparse.ArgumentParser(description='The Mesh Converter.')
parser.add_argument('-p', '--in-vpos', required=True, type=str, action='store', dest='in_vpos', metavar='vpos.bin')
parser.add_argument('-n', '--in-vbml', required=True, type=str, action='store', dest='in_vnml', metavar='vnml.bin')
parser.add_argument('-u', '--in-vuv', required=True, type=str, action='store', dest='in_vuv', metavar='vuv.bin')
parser.add_argument('-i', '--in-findices', required=True, type=str, action='store', dest='in_findices', metavar='findices.bin')
parser.add_argument('-o', '--out-obj', required=True, type=str, action='store', dest='out_obj', metavar='mesh.obj')
parser.add_argument('-m', '--out-mtl', required=True, type=str, action='store', dest='out_mtl', metavar='mesh.mtl')
Vector = tuple[float]
Indices = tuple[int]
def GetFileLength(fs: io.BufferedReader) -> int:
pos = fs.tell()
fs.seek(0, io.SEEK_END)
fsize = fs.tell()
fs.seek(pos, io.SEEK_SET)
return fsize
def EvaluateCount(filename: str, unit_size: int) -> int:
with open(filename, 'rb') as fs:
filesize = GetFileLength(fs)
count, modrem = divmod(filesize, unit_size)
if modrem != 0:
raise Exception("invalid file length")
return count
def AssertFileSize(fs: io.BufferedReader, expected_size: int):
if expected_size != GetFileLength(fs):
raise Exception("invalid file length")
def ReadFloats(filename: str, count: int) -> tuple[float]:
with open(filename, 'rb') as fs:
# construct class
cstruct = struct.Struct(f'<{count}f')
# assert file size
AssertFileSize(fs, cstruct.size)
# read
return cstruct.unpack(fs.read(cstruct.size))
def ReadShorts(filename: str, count: int) -> tuple[float]:
with open(filename, 'rb') as fs:
# construct class
cstruct = struct.Struct(f'<{count}H')
# assert file size
AssertFileSize(fs, cstruct.size)
# read
return cstruct.unpack(fs.read(cstruct.size))
def RecoupleTuple(fulllist: tuple, couple_count: int) -> tuple[tuple]:
count, modrem = divmod(len(fulllist), couple_count)
if modrem != 0:
raise Exception("invalid tuple length")
return tuple(map(lambda x: tuple(fulllist[x * couple_count:x * couple_count + couple_count]), range(count)))
def GenerateObj(filename: str, vpos: tuple[Vector], vnml: tuple[Vector], vuv: tuple[Vector], findices: tuple[Indices]):
with open(filename, 'w', encoding='utf-8') as fs:
for v in vpos:
fs.write('v {0} {1} {2}\n'.format(v[0], v[1], v[2]))
for v in vnml:
fs.write('vn {0} {1} {2}\n'.format(v[0], v[1], v[2]))
for v in vuv:
fs.write('vt {0} {1}\n'.format(v[0], v[1]))
for f in findices:
fs.write('f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n'.format(f[0] + 1, f[1] + 1, f[2] + 1))
fs.write('g obj\n')
if __name__ == '__main__':
# parse arg
args = parser.parse_args()
#input("Prepare VertexPositions please.")
vertexcount = EvaluateCount(args.in_vpos, 3 * 4) # 3 float(4 bytes)
print(f'Vertex Count Evaluated: {vertexcount}')
vpos = RecoupleTuple(ReadFloats(args.in_vpos, 3 * vertexcount), 3)
#input("Prepare VertexNormals please.")
vnml = RecoupleTuple(ReadFloats(args.in_vnml, 3 * vertexcount), 3)
#input("Prepare VertexUVs please.")
vuv = RecoupleTuple(ReadFloats(args.in_vuv, 2 * vertexcount), 2)
#input("Prepare FaceIndices please.")
facecount = EvaluateCount(args.in_findices, 3 * 2) # 3 WORD(2 bytes)
print(f'Face Count Evaluated: {facecount}')
findices = RecoupleTuple(ReadShorts(args.in_findices, 3 * facecount), 3)
GenerateObj(args.out_obj, vpos, vnml, vuv, findices)
print('Done')

View File

@@ -0,0 +1,20 @@
# Tools
The developer need to know the loaded data whether is correct when testing LibCmo. So we create this folder and you can use Unvirt and the tools located in this folder to test the correction of loaded data.
Unvirt can show the data of each CKObject, such as Texture, Mesh and etc. For example, Unvirt can provide vertex's position, normal, UV, even the face's indices data for CKMesh. You can use tools to broswer memory to get them, but you couldn't evaluate them how they shape a mesh. This is the reason why this folder existed and in this README I will tell you how to debug the loaded data.
I suggest you to use HxD to broswer memory, but if you have other softwares, use it freely.
## CKTexture
* Install [PixelViewer](https://github.com/carina-studio/PixelViewer) first.
* Change profile to `BGRA_8888` (actually is little-endian RGBA8888, but I think the developer of PixelViewer get confused).
* The image resolution can be gotten from Uvirt. Set it in PixelViewer.
* The image address also can be gotten from Unvirt. Save the memory image data to local file and open it by PixelViewer.
## CKMesh
* Have a executable Python.
* Save VertexPosition, VertexNormal, VertexUV, FaceIndices data into file according to the given memory address by Unvirt.
* Call `MeshConv.py`, set the argument properly, then you will get a converted Wavefront OBJ file.