Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .i3d files #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PS2/I3D/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# I3D file
* **i3d2obj.py** - Converts an .i3d or a .mdl (Rule of Rose) model file to OBJ.
* Prerequisites: [NumPy](https://numpy.org)
## Supported games
* Ape Escape 3 (PS2, 2005)
* Rule of Rose (PS2, 2006)
49 changes: 25 additions & 24 deletions PS2/Rule of Rose/mdl2obj.py → PS2/I3D/i3d2obj.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Converts a Rule of Rose (PS2) I3D model file (.MDL) to OBJ.
# Converts a .i3d model file or a Rule of Rose (PS2) .MDL model file to OBJ.

import argparse
import argparse
Expand All @@ -9,7 +9,7 @@
import struct

parser = argparse.ArgumentParser(description='''
Converts a Rule of Rose (PS2) I3D model file (.MDL) to OBJ.
Converts a .i3d model file or a Rule of Rose (PS2) .MDL model file to OBJ.
''')

def err(msg):
Expand All @@ -31,7 +31,7 @@ def getfloat32(b, offs):
def getnfloat32(b, offs, n):
return struct.unpack('<' + 'f'*n, b[offs:offs+4*n])

parser.add_argument('mdlpath', help='Input path of .MDL file', nargs=1)
parser.add_argument('mdlpath', help='Input path of .MDL/.I3D file', nargs=1)
args = parser.parse_args()

if len(args.mdlpath[0]) == 0:
Expand All @@ -42,29 +42,30 @@ def getnfloat32(b, offs, n):
def ReadRpkFile(f, index):
f.seek(0)
header = f.read(0x20)
if header[:4] != b'RTPK':
err("Not an RTPK archive!")

numfiles = getuint16(header, 0xE)
if index < 0 or index >= numfiles:
err("File index {} out of range in RTPK archive".format(index))
totalsize = getuint32(header, 0x4)
filesize = 0
fileoffs = 0

if header[0xA] == 0x2: # Offset table only
f.seek(index * 0x4 + 0x20)
fileoffs = getuint32(f.read(4))
if index == numfiles - 1:
filesize = totalsize - fileoffs
else:
filesize = getuint32(f.read(4)) - fileoffs
elif header[0xA] == 0x3: # Size and offset tables
f.seek(index * 0x4 + 0x20)
filesize = getuint32(f.read(4))
f.seek((numfiles + index) * 4 + 0x20)
fileoffs = getuint32(f.read(4))

if header[:4] == b'RTPK':
numfiles = getuint16(header, 0xE)
if index < 0 or index >= numfiles:
err("File index {} out of range in RTPK archive".format(index))

if header[0xA] == 0x2: # Offset table only
f.seek(index * 0x4 + 0x20)
fileoffs = getuint32(f.read(4))
if index == numfiles - 1:
filesize = totalsize - fileoffs
else:
filesize = getuint32(f.read(4)) - fileoffs
elif header[0xA] == 0x3: # Size and offset tables
f.seek(index * 0x4 + 0x20)
filesize = getuint32(f.read(4))
f.seek((numfiles + index) * 4 + 0x20)
fileoffs = getuint32(f.read(4))
elif header[:7] == b'I3D_BIN':
filesize = totalsize
else:
err("Not an RTPK archive or I3D file!")
f.seek(fileoffs)
return f.read(filesize)

Expand Down Expand Up @@ -242,7 +243,7 @@ def maybe_mask_value(val, index, cycle, use_mask):
buf = ReadRpkFile(f, 1)[0x10:]
f.close()
if len(buf) < 0x10:
err('MDL model file is too small! {} bytes'.format(len(buf)))
err('I3D model file is too small! {} bytes'.format(len(buf)))

# Construct the entire node tree recursively.
rootNode = Node(buf, 0)
Expand Down
5 changes: 1 addition & 4 deletions PS2/Rule of Rose/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# Rule of Rose (PS2, 2006)

* **mdl2obj.py** - Converts an I3D model file to OBJ.
* Prerequisites: [NumPy](https://numpy.org)
* **rpkextract.py** - Extracts files from an RPK archive.
* **rpkextract.py** - Extracts files from an RPK archive.