#*************************************
#Author : Chrrox, Co-Author : Codeman02
#*************************************
#Noesis Python model import+export test module, imports/exports some data from/to a made-up format
from inc_noesis import *
import noesis
#rapi methods should only be used during handler callbacks
import rapi
#registerNoesisTypes is called by Noesis to allow the script to register formats.
#Do not implement this function in script files unless you want them to be dedicated format modules!
def registerNoesisTypes():
handle = noesis.register("Resident Evil 6", ".re6pc")
noesis.setHandlerTypeCheck(handle, re6CheckType)
noesis.setHandlerLoadModel(handle, re6LoadModel) #see also noepyLoadModelRPG
#noesis.setHandlerWriteModel(handle, noepyWriteModel)
#noesis.setHandlerWriteAnim(handle, noepyWriteAnim)
noesis.logPopup()
return 1
#check if it's this type based on the data
def re6CheckType(data):
bs = NoeBitStream(data)
idMagic = bs.readInt()
if idMagic != 0x00444F4
return 0
return 1
#load the model
def re6LoadModel(data, mdlList):
ctx = rapi.rpgCreateContext()
#rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
bs = NoeBitStream(data)
#bs.setEndian(NOE_BIGENDIAN)
idMagic = bs.readInt()
header_version = bs.readUShort() # mod file version
header_bonecount = bs.readUShort() # word Bones[1 to bonecount]
header_grpcount = bs.readUShort() # word Groups[1 to grpcount]
header_Matcount = bs.readUShort() # word Materials[1 to Matcount]
header_vertexcount = bs.readInt() # total vertex in vertex buffer
header_TriangleCount = bs.readInt() # total face count
header_VertexIds = bs.readInt() # Integer Triangle[1 to TriangleCount]
header_vertexbuffersize = bs.readInt() # vertex buffer data size in bytes to alloc on the fly when reading
header_padding = bs.readInt() # always &H00000000 ???? no, sometime have a value :0/
header_bonegroupsA = bs.readInt() # bone groups sections used for skeleton
header_groupidtrc = bs.readInt() # ????
header_ptrBoneOffset = bs.readInt() # zero if only one bone
header_groupidtrOf = bs.readInt() # unused
header_ptr_group = bs.readInt() # groups array info Offset
header_ptr_vertex = bs.readInt() # vertex buffer pos in file
header_ptr_triangle = bs.readInt() # triangle buffer pos in file(index buffer)
modHeader2 = bs.readInt() # end of file - 4 ????
bs.seek(header_ptr_group, NOESEEK_ABS)#modHeader2[9]#== seekset
meshInfo = []
for i in range(0, header_grpcount):
unk00 = bs.readUShort()
vertCount = bs.readUShort()
unk01 = bs.readUByte()
unk02 = bs.readUByte()
groupid = bs.readUByte() # groupid
lodLevel = bs.readUByte()
unk04 = bs.readUByte()
vertFlag = bs.readUByte()
vertStride = bs.readUByte()
unk05 = bs.readUByte()
vertStart = bs.readUInt()
vertBase = bs.readUInt()
fvfInfo = bs.readUInt()
faceStart = bs.readUInt()
faceCount = bs.readUInt()
faceBase = bs.readUInt()#?
unk07 = bs.readUShort()
unk08 = bs.readUShort()
vertStart2 = bs.readUShort()
vertCount2 = bs.readUShort()
unk09 = bs.readInt()#?
# 0 1 2 3 4 5 6 7 8 9
meshInfo.append([vertCount,vertStride,vertStart,vertBase,faceStart,faceCount,faceBase,lodLevel,fvfInfo,groupid])
#print(meshInfo[i])
for i in range(0, header_grpcount):
bs.seek(header_ptr_vertex + meshInfo[i][3], NOESEEK_ABS)#vert
bs.seek(meshInfo[i][1] * meshInfo[i][2], NOESEEK_REL)#vert
print(meshInfo[i][7])
if (meshInfo[i][1] >= 0x14) and ((meshInfo[i][7] == 0x1) or (meshInfo[i][7] == 0xFF)or (meshInfo[i][7] == 0x3)) :
bfound=1
rapi.rpgSetName("LOD_" + str(hex(meshInfo[i][7])) + "_" + str(i) + "_" + str(meshInfo[i][1])+ "_" + str(hex(meshInfo[i][8])) + "_" + str(bs.tell())) #+ "_" + str((bs.tell()))
vertBuff = bs.readBytes(meshInfo[i][0] * meshInfo[i][1])
if meshInfo[i][8] == 0xB0983013:#12 == morph target objects: vertexpos + normal
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xDB7DA014:#16
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 12)
elif meshInfo[i][8] == 0xB6681034:#16
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x0CB68015:#20
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xA8FAB018:#20
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xA7D7D036:#20
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xC31F201C:#24
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xCBF6C01A:#24
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x207D6037:#24
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xD1A47038:#24
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xD8297028:#24
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x2BE814D4:#28
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x7CD414D4:#28
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x14D40020:#28
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 20)
elif meshInfo[i][8] == 0xA320C016:#28
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x49B4F029:#28
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x5E7F202C:#28
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xD877801B:#32
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xB86DE02A:#32
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x926FD02E:#32
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xA14E003C:#32
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xB392101F:#36
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0xBB424024:#36
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
#rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 24)
elif meshInfo[i][8] == 0x63B6C02F:#36
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
elif meshInfo[i][8] == 0x64593023:#40
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1],20) #or 32 for uv2
elif meshInfo[i][8] == 0x2F55C03
#64
rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, meshInfo[i][1], 16)
else:
bfound=0
print("unkown FVF "+ str(hex(meshInfo[i][8])))
rapi.rpgBindUV1Buffer(None, noesis.RPGEODATA_FLOAT, 0)
#rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_SHORT, meshInfo[i][1], 0)
if bfound == 1:
print("face base : " + str(hex(meshInfo[i][6])))
bs.seek(header_ptr_triangle + (2 * meshInfo[i][4])+(2 * meshInfo[i][6]), NOESEEK_ABS)#faceoff
faceData = []
for a in range(0, meshInfo[i][5]):
face = bs.readUShort() - meshInfo[i][2]
faceData.append(face)
faceBuff = struct.pack("<" + 'H'*len(faceData), *faceData)
rapi.rpgCommitTriangles(faceBuff, noesis.RPGEODATA_USHORT, meshInfo[i][5], noesis.RPGEO_TRIANGLE, 1)
mdl = rapi.rpgConstructModelSlim()
mdlList.append(mdl)
rapi.rpgClearBufferBinds()
return 1