def bindBuffers(self, vertexData, bindWeights = True): rapi.rpgClearBufferBinds() if self.posType != 0: bindTypes = (0, noesis.RPGEODATA_BYTE, noesis.RPGEODATA_SHORT, noesis.RPGEODATA_FLOAT) rapi.rpgBindPositionBufferOfs(vertexData, bindTypes[self.posType], self.vertexSize, self.posOfs) if self.normalType != 0: bindTypes = (0, noesis.RPGEODATA_BYTE, noesis.RPGEODATA_SHORT, noesis.RPGEODATA_FLOAT) rapi.rpgBindNormalBufferOfs(vertexData, bindTypes[self.normalType], self.vertexSize, self.normalOfs) if self.uvType != 0: bindTypes = (0, noesis.RPGEODATA_UBYTE, noesis.RPGEODATA_USHORT, noesis.RPGEODATA_FLOAT) rapi.rpgBindUV1BufferOfs(vertexData, bindTypes[self.uvType], self.vertexSize, self.uvOfs) if self.colorType == 7: #binding is not natively supported for the other color formats. if you want to use them, you need to decode them before binding. rapi.rpgBindColorBufferOfs(vertexData, noesis.RPGEODATA_UBYTE, self.vertexSize, self.colorOfs, 4) if bindWeights is True and self.weightType != 0: bindTypes = (0, noesis.RPGEODATA_UBYTE, noesis.RPGEODATA_USHORT, noesis.RPGEODATA_FLOAT) rapi.rpgBindBoneWeightBufferOfs(vertexData, bindTypes[self.weightType], self.vertexSize, self.weightOfs, self.numWeights)
def noepyLoadModel(data, mdlList): ctx = rapi.rpgCreateContext() bs = NoeBitStream(data) #rapi.rpgSetPosScaleBias((-1,-1,1),(0,0,0)) boneList = [] boneCount = bs.readInt() boneOffset = bs.tell() + bs.readInt() texCount = bs.readInt() texOffset = bs.tell() + bs.readInt() matCount = bs.readInt() matOffset = bs.tell() + bs.readInt() meshCount = bs.readInt() meshOffset = bs.tell() + bs.readInt() bs.seek(boneOffset, NOESEEK_ABS) for i in range(0, boneCount): boneName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") boneMtx = NoeMat44.fromBytes(bs.readBytes(0x40)).toMat43() bs.readBytes(0x40) boneParent = bs.readInt() bs.readBytes(0x8) pos = NoeVec3.fromBytes(bs.readBytes(12)) bs.readBytes(0x8) quat = NoeQuat.fromBytes(bs.readBytes(16)) NoeVec3.fromBytes(bs.readBytes(12)) bs.readBytes(0x14) boneMtx = quat.toMat43() boneMtx[3] = pos newBone = NoeBone(i, boneName, boneMtx, None, boneParent) boneList.append(newBone) boneList = rapi.multiplyBones(boneList) texInfo = [] texList = [] bs.seek(texOffset, NOESEEK_ABS) for i in range(0, texCount): texName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") texStart = bs.tell() + bs.readInt() bs.readBytes(0xC) texInfo.append([texName, texStart]) #print(texInfo) for i in range(0, texCount): bs.seek(texInfo[i][1], NOESEEK_ABS) bs.readBytes(0xC) palOff = bs.tell() + bs.readInt() texType, unk02, pixWidth, pixHeight, unk03, unk04 = bs.read("6H") texSize = bs.readInt() texOff = bs.tell() + bs.readInt() bs.seek(texOff, NOESEEK_ABS) texData = bs.readBytes(texSize) bs.seek(palOff, NOESEEK_ABS) unk11, unk22 = bs.read("2H") palSize, Null = bs.read("2I") palStart = bs.tell() + bs.readInt() bs.seek(palStart, NOESEEK_ABS) palData = [] for a in range(0, palSize // 4): pR, pG, pB, pA = bs.read("4B") if pR == 0 and pG == 255 and pB == 0 and pA == 255: pG = 0 pA = 0 palData.append(pR) palData.append(pG) palData.append(pB) palData.append(pA) palData = struct.pack("<" + 'B' * len(palData), *palData) if texType == 5: pix = rapi.imageUntwiddlePSP(texData, pixWidth, pixHeight, 8) pix = rapi.imageDecodeRawPal(pix, palData, pixWidth, pixHeight, 8, "r8g8b8a8") elif texType == 4: pix = rapi.imageUntwiddlePSP(texData, pixWidth, pixHeight, 4) pix = rapi.imageDecodeRawPal(pix, palData, pixWidth, pixHeight, 4, "r8g8b8a8") texList.append( NoeTexture(texInfo[i][0], pixWidth, pixHeight, pix, noesis.NOESISTEX_RGBA32)) matList = [] bs.seek(matOffset, NOESEEK_ABS) for i in range(0, matCount): matName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") bs.readBytes(0xC) texID = bs.readInt() unk01, unk02, unk03, unk04 = bs.read("4B") bs.readBytes(0x8) material = NoeMaterial(matName, "") if texID >= 0: material.setTexture(texInfo[texID][0]) #material.setOpacityTexture(texInfo[texID][0]) matList.append(material) meshList = [] bs.seek(meshOffset, NOESEEK_ABS) for i in range(0, meshCount): meshName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") mshCount = bs.readInt() unk11 = bs.readInt() meshStart = bs.tell() + bs.readInt() bs.readBytes(0xC) meshList.append([meshName, meshStart, mshCount, unk11]) #print(meshList) for a in range(0, len(meshList)): mshInfo = [] #print(meshList[a][0]) bs.seek(meshList[a][1], NOESEEK_ABS) for b in range(0, meshList[a][2]): unk20 = bs.readInt() matID = bs.readInt() mshC = bs.readInt() MshOff = bs.tell() + bs.readInt() mshInfo.append([matID, mshC, MshOff]) #print(mshInfo) mshInfo2 = [] for b in range(0, len(mshInfo)): bs.seek(mshInfo[b][2], NOESEEK_ABS) for c in range(0, mshInfo[b][1]): meshPc = bs.readInt() vType = bs.readInt() meshPc2 = bs.readInt() mshPo = bs.tell() + bs.readInt() mshPo2 = bs.tell() + bs.readInt() mshInfo2.append([ meshPc, vType, meshPc2, mshPo, mshPo2, matList[(mshInfo[b][0])].name ]) #print(mshInfo2) for b in range(0, len(mshInfo2)): mshInfo3 = [] rapi.rpgSetMaterial(mshInfo2[b][5]) bs.seek(mshInfo2[b][3], NOESEEK_ABS) idxList = [[0, 0, 0, 0, 0, 0, 0, 0]] for c in range(0, mshInfo2[b][2]): idxList[0][c] = bs.readInt() bs.seek(mshInfo2[b][4], NOESEEK_ABS) #print(idxList) for c in range(0, mshInfo2[b][0]): mshId2 = bs.readInt() vertCount = bs.readInt() vertStart = bs.tell() + bs.readInt() mshInfo3.append([mshId2, vertCount, vertStart]) #print(mshInfo3) for c in range(0, len(mshInfo3)): #print(mshInfo3[c]) bs.seek(mshInfo3[c][2], NOESEEK_ABS) rapi.rpgSetName(meshList[a][0]) #rapi.rpgSetName(meshList[a][0] + "_" + str(b) + "_" + str(c) + "_" + str(mshInfo2[b][1])) vertStride = 0 if mshInfo2[b][1] == 7: vertStride = 0x18 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0xC) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x8, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0) elif mshInfo2[b][1] == 24: vertStride = 0x1C vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0xC, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x4) elif mshInfo2[b][1] == 25: vertStride = 0x1C vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0xC, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x4) elif mshInfo2[b][1] == 26: vertStride = 0x20 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x14) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x10, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x8) elif mshInfo2[b][1] == 27: vertStride = 0x20 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x14) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x10, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x8) elif mshInfo2[b][1] == 28: vertStride = 0x24 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x18) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x14, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0xC) elif mshInfo2[b][1] == 29: vertStride = 0x24 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x18) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x14, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0xC) elif mshInfo2[b][1] == 30: vertStride = 0x28 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x1C) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x18, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) elif mshInfo2[b][1] == 23: vertStride = 0x28 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x1C) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x18, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) else: print(bs.tell()) print("unknown found " + str(mshInfo2[b][1])) vs = NoeBitStream(vertBuff) tmp = [] tmp2 = [] weight = [] index = [] if vertStride == 0x18: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] index.append(idxList[0][0]) index.append(idxList[0][1]) index.append(idxList[0][2]) index.append(idxList[0][3]) index.append(idxList[0][4]) index.append(idxList[0][5]) index.append(idxList[0][6]) index.append(idxList[0][7]) weight.append(w1) weight.append(w2) weight.append(w3) weight.append(w4) weight.append(w5) weight.append(w6) weight.append(w7) weight.append(w8) vs.readBytes(0xC) tmp.append( [vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x1C: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [ vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] index.append(idxList[0][0]) index.append(idxList[0][1]) index.append(idxList[0][2]) index.append(idxList[0][3]) index.append(idxList[0][4]) index.append(idxList[0][5]) index.append(idxList[0][6]) index.append(idxList[0][7]) weight.append(w1) weight.append(w2) weight.append(w3) weight.append(w4) weight.append(w5) weight.append(w6) weight.append(w7) weight.append(w8) vs.readBytes(0xC) tmp.append( [vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x20: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [ vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, 0.0, 0.0, 0.0, 0.0 ] index.append(idxList[0][0]) index.append(idxList[0][1]) index.append(idxList[0][2]) index.append(idxList[0][3]) index.append(idxList[0][4]) index.append(idxList[0][5]) index.append(idxList[0][6]) index.append(idxList[0][7]) weight.append(w1) weight.append(w2) weight.append(w3) weight.append(w4) weight.append(w5) weight.append(w6) weight.append(w7) weight.append(w8) vs.readBytes(0xC) tmp.append( [vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x24: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [ vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, 0.0, 0.0 ] index.append(idxList[0][0]) index.append(idxList[0][1]) index.append(idxList[0][2]) index.append(idxList[0][3]) index.append(idxList[0][4]) index.append(idxList[0][5]) index.append(idxList[0][6]) index.append(idxList[0][7]) weight.append(w1) weight.append(w2) weight.append(w3) weight.append(w4) weight.append(w5) weight.append(w6) weight.append(w7) weight.append(w8) vs.readBytes(0xC) tmp.append( [vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x28: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [ vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF ] index.append(idxList[0][0]) index.append(idxList[0][1]) index.append(idxList[0][2]) index.append(idxList[0][3]) index.append(idxList[0][4]) index.append(idxList[0][5]) index.append(idxList[0][6]) index.append(idxList[0][7]) weight.append(w1) weight.append(w2) weight.append(w3) weight.append(w4) weight.append(w5) weight.append(w6) weight.append(w7) weight.append(w8) vs.readBytes(0xC) tmp.append( [vs.readUInt(), vs.readUInt(), vs.readUInt()]) indexBuff = struct.pack('B' * len(index), *index) weightBuff = struct.pack('f' * len(weight), *weight) rapi.rpgBindBoneIndexBuffer(indexBuff, noesis.RPGEODATA_BYTE, 8, 8) rapi.rpgBindBoneWeightBuffer(weightBuff, noesis.RPGEODATA_FLOAT, 0x20, 8) flip = 0 step = 1 if mshInfo3[c][0] == 0: step = 3 for d in range(0, mshInfo3[c][1] - 2, step): if (tmp[d] != tmp[(d + 1)]) and (tmp[d] != tmp[ (d + 2)]) and (tmp[d + 1] != tmp[(d + 2)]): tmp2.append(d) tmp2.append(d + 1 + flip) tmp2.append(d + 2 - flip) if mshInfo3[c][0] != 0: flip = 1 - flip else: flip = 0 #print(d) faceBuff = struct.pack('H' * len(tmp2), *tmp2) if len(faceBuff) > 3: rapi.rpgCommitTriangles(faceBuff, noesis.RPGEODATA_USHORT, len(tmp2), noesis.RPGEO_TRIANGLE, 1) rapi.rpgClearBufferBinds() mdl = rapi.rpgConstructModel() mdl.setModelMaterials(NoeModelMaterials(texList, matList)) mdlList.append(mdl) mdl.setBones(boneList) return 1
def pso2LoadModel(data, mdlList): ctx = rapi.rpgCreateContext() bs = NoeBitStream(data) Bones = [] Bone_Pallet = [] Bone_Matrix = [] Bone_Name = [] Bone_Parent = [] vertSize = [] vertCount = [] vtxeOffset = [] vtxlOffset = [] psetOffset = [] boneFileName = rapi.getDirForFilePath(rapi.getInputName()) + rapi.getLocalFileName(rapi.getInputName()).rstrip(".aqo") + ".aqn" if (rapi.checkFileExists(boneFileName)): boneData = rapi.loadIntoByteArray(boneFileName) if boneData is not None: bd = NoeBitStream(boneData) bd.seek(0xC, NOESEEK_ABS) start = bd.readInt() bd.seek(start + 0x10, NOESEEK_ABS) while not bd.checkEOF(): chunkStart = bd.tell() chunkType = bd.readBytes(4).decode("ASCII") chunkSize = bd.readInt() subChunkType = bd.readBytes(4).decode("ASCII") #print([chunkType,chunkSize,subChunkType]) for case in switch(subChunkType): if case('AQGF'): bd.seek(chunkStart + chunkSize, NOESEEK_ABS) break if case('ROOT'): bd.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('NODE'): bd.seek(6, NOESEEK_REL) while bd.tell() < chunkStart + 8 + chunkSize: nodeChunkStart = bd.tell() nodeChunkType = bd.readUShort() #print([nodeChunkType,nodeChunkStart]) for case in switch(nodeChunkType): if case(0x903): nodeTest1 = bd.readInt() break if case(0x804): BoneParent = bd.readInt() Bone_Parent.append(BoneParent) break if case(0x80F): nodeTest1 = bd.readInt() break if case(0x805): nodeTest1 = bd.readInt() break if case(0x806): nodeTest1 = bd.readInt() break if case(0x4A07): bd.seek(0xD, NOESEEK_REL) break if case(0x4A08): bd.seek(0xD, NOESEEK_REL) break if case(0x4A09): bd.seek(0xD, NOESEEK_REL) break if case(0xCA0A): bd.seek(0x2, NOESEEK_REL) BoneMatrix = NoeMat44.fromBytes(bd.readBytes(64)).toMat43() Bone_Matrix.append(BoneMatrix.inverse()) break if case(0x90B): nodeTest1 = bd.readInt() break if case(0x90C): nodeTest1 = bd.readInt() break if case(0x20D): nSize = bd.readUByte() boneName = bd.readBytes(nSize).decode("ASCII") Bone_Name.append(boneName) break if case(0xFD): break break if case('NODO'): bd.seek(bd.getSize(), NOESEEK_ABS) break if case(): # default, could also just omit condition or 'if True' bd.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) # No need to break here, it'll stop anyway for a in range(0, len(Bone_Matrix)): bn = NoeBone(a, Bone_Name[a], Bone_Matrix[a], None, Bone_Parent[a]) Bones.append(bn) aqoMagic = bs.readInt() while not bs.checkEOF(): chunkStart = bs.tell() chunkType = bs.readBytes(4).decode("ASCII") chunkSize = bs.readInt() subChunkType = bs.readBytes(4).decode("ASCII") #print([chunkType,chunkSize,subChunkType]) for case in switch(subChunkType): if case('AQGF'): bs.seek(chunkStart + chunkSize, NOESEEK_ABS) break if case('ROOT'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('OBJC'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('VSET'): while bs.tell() < chunkStart + 8 + chunkSize: vsetChunkStart = bs.tell() vsetChunkType = bs.readUShort() #print([vsetChunkStart,vsetChunkType]) for case in switch(vsetChunkType): if case(0x9B6): vsetVertSize = bs.readInt() vertSize.append(vsetVertSize) #print([vsetChunkType,vsetVertSize]) break if case(0x9BF): vsetUnk01 = bs.readInt() break if case(0x9B9): vsetVertCount = bs.readInt() vertCount.append(vsetVertCount) #print([vsetChunkType,vsetVertCount]) break if case(0x9C4): vsetUnk01 = bs.readInt() break if case(0x9BD): vsetUnk01 = bs.readInt() if vsetUnk01 == 0: Bone_Pallet.append(()) break if case(0x86BE): test = bs.readByte() test = bs.readUByte() BonePallet = bs.read("H"*(test + 1)) Bone_Pallet.append(BonePallet) break if case(0x6BE): test = bs.readByte() test = bs.readUByte() Bone_Pallet.append(()) break if case(0x9C8): vsetUnk01 = bs.readInt() break if case(0x9CC): vsetUnk01 = bs.readInt() break if case(0x9C9): vsetUnk01 = bs.readInt() break if case(0xFD): break bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('VTXE'): vtxeOffset.append([chunkStart,chunkSize]) bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('MESH'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('REND'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('SHAD'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('SHAP'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('TSTA'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('TSET'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('VTXL'): vtxlOffset.append([chunkStart,chunkSize]) bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('TEXF'): bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case('PSET'): psetOffset.append(chunkStart) bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) break if case(): # default, could also just omit condition or 'if True' bs.seek(chunkStart + 8 + chunkSize, NOESEEK_ABS) # No need to break here, it'll stop anyway #bs.readBytes(8).decode("ASCII").rstrip("\0") FaceOff = psetOffset[0] + 18 rapi.rpgSetUVScaleBias(NoeVec3 ((1.0, -1.0, 1.0)), NoeVec3 ((1.0, 1.0, 1.0))) for i in range(0, len(vertSize)): bs.seek(vtxlOffset[i][0] + 18, NOESEEK_ABS) test = bs.readByte() if test == 8: test = bs.readUByte() VertBuff = bs.readBytes(vtxlOffset[i][1] - 12) elif test == 24: test = bs.readInt() VertBuff = bs.readBytes(vtxlOffset[i][1] - 15) else: test = bs.readUShort() VertBuff = bs.readBytes(vtxlOffset[i][1] - 13) bs.seek(vtxeOffset[i][0] + 18, NOESEEK_ABS) for j in range(0, (vtxeOffset[i][1] - 10) // 26): vtxeChunkTypeid = bs.readUShort() vtxeChunkType = bs.readInt() vtxeChunkType2id = bs.readUShort() vtxeChunkType2 = bs.readInt() vtxeChunkPosId = bs.readUShort() vtxeChunkPos = bs.readInt() vtxeChunkUnkid = bs.readUShort() vtxeChunkUnk = bs.readInt() vtxeChunkTerm = bs.readUShort() if vtxeChunkType == 0: rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, vertSize[i], vtxeChunkPos) elif vtxeChunkType == 1: rapi.rpgBindBoneWeightBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, vertSize[i], vtxeChunkPos, 4) elif vtxeChunkType == 2: #rapi.rpgBindNormalBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, vertSize[i], vtxeChunkPos) pass elif vtxeChunkType == 3: rapi.rpgBindColorBufferOfs(VertBuff, noesis.RPGEODATA_UBYTE, vertSize[i], vtxeChunkPos, 4) elif vtxeChunkType == 4: pass#4 bytes as floats 2nd vertex color? elif vtxeChunkType == 11: rapi.rpgBindBoneIndexBufferOfs(VertBuff, noesis.RPGEODATA_UBYTE, vertSize[i], vtxeChunkPos, 4) elif vtxeChunkType == 16: rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, vertSize[i], vtxeChunkPos) elif vtxeChunkType == 17: rapi.rpgBindUV2BufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, vertSize[i], vtxeChunkPos) elif vtxeChunkType == 32: pass#tangents? elif vtxeChunkType == 33: pass#binormals/tangents? else: print(vtxeChunkType) bs.seek(FaceOff, NOESEEK_ABS) bs.seek(0x1A, NOESEEK_REL) test = bs.readByte() if test == 8: FaceCount = bs.readUByte() FaceBuff = bs.readBytes((FaceCount + 1) * 2) elif test == 16: FaceCount = bs.readUShort() FaceBuff = bs.readBytes((FaceCount + 1) * 2) else: FaceCount = bs.readInt() FaceBuff = bs.readBytes((FaceCount + 1) * 2) bs.seek(0x8, NOESEEK_REL) FaceOff = bs.tell() rapi.rpgSetName(str(i)) rapi.rpgSetMaterial(str(i)) material = NoeMaterial((str(i)), "") if len(Bone_Pallet) > 0: if len(Bone_Pallet[i]) > 0: rapi.rpgSetBoneMap(Bone_Pallet[i]) rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount + 1, noesis.RPGEO_TRIANGLE_STRIP, 1) mdl = rapi.rpgConstructModel() mdl.setBones(Bones) mdlList.append(mdl) rapi.rpgClearBufferBinds() return 1
def bindVertStride(self, modelName, rapi, des, vertBuff, vertStride, bindBones): useAltStride44OrderFor = [] if modelName == "SV1310_PS4": useAltStride44OrderFor.append(0x47a70) if modelName == "SV0803_PS4": useAltStride44OrderFor.append(0x592c0) # not implemented: # 4, 8, 12 - do not have IXBF # 16 - unknown format, do not have IXBF probably, 20 - not used by any game model if vertStride == 24: # 0xC, 0x10 unk floats rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x14) elif vertStride == 28: # 0xC, 0x10, 0x14 unk floats rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x18) elif vertStride == 32: # 0xC, 0x10, 0x14 unk floats, 0x1C unk rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x18) elif vertStride == 36: # 0xC, 0x10, 0x14 unk floats, 0x1C unk rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x18) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x20, 4) elif vertStride == 40: # 0xC, 0x10, 0x14 unk floats, 0x1C unk rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x18) bindBones(0x20, 0x24, vertStride) elif vertStride == 44: # 0xC, 0x10, 0x14 unk floats, 0x1C unk rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x18) if des.farOffset in useAltStride44OrderFor: bindBones(0x24, 0x28, vertStride) else: bindBones(0x20, 0x24, vertStride) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x28, 4) elif vertStride == 48: # 0xC, 0x10, 0x14 unk floats, 0x1C, 0x1C, 0x20, 0x24, 0x28 unk rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, vertStride, 0x18) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x2C, 4) else: rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, vertStride) warn("Don't know how to parse vertex stride: {}.".format( vertStride))
def noepyLoadModel(data, mdlList): ctx = rapi.rpgCreateContext() bs = NoeBitStream(data) #rapi.rpgSetPosScaleBias((-1,-1,1),(0,0,0)) boneList = [] boneCount = bs.readInt() boneOffset = bs.tell() + bs.readInt() texCount = bs.readInt() texOffset = bs.tell() + bs.readInt() matCount = bs.readInt() matOffset = bs.tell() + bs.readInt() meshCount = bs.readInt() meshOffset = bs.tell() + bs.readInt() bs.seek(boneOffset, NOESEEK_ABS) for i in range(0, boneCount): boneName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") boneMtx = NoeMat44.fromBytes(bs.readBytes(0x40)).toMat43() bs.readBytes(0x40) boneParent = bs.readInt() bs.readBytes(0x8) pos = NoeVec3.fromBytes(bs.readBytes(12)) bs.readBytes(0x8) quat = NoeQuat.fromBytes(bs.readBytes(16)) NoeVec3.fromBytes(bs.readBytes(12)) bs.readBytes(0x14) boneMtx = quat.toMat43() boneMtx[3] = pos newBone = NoeBone(i, boneName, boneMtx, None, boneParent) boneList.append(newBone) boneList = rapi.multiplyBones(boneList) texInfo = [] texList = [] bs.seek(texOffset, NOESEEK_ABS) for i in range(0, texCount): texName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") texStart = bs.tell() + bs.readInt() bs.readBytes(0xC) texInfo.append([texName,texStart]) #print(texInfo) for i in range(0, texCount): bs.seek(texInfo[i][1], NOESEEK_ABS) bs.readBytes(0xC) palOff = bs.tell() + bs.readInt() texType, unk02, pixWidth, pixHeight, unk03, unk04 = bs.read("6H") texSize = bs.readInt() texOff = bs.tell() + bs.readInt() bs.seek(texOff, NOESEEK_ABS) texData = bs.readBytes(texSize) bs.seek(palOff, NOESEEK_ABS) unk11, unk22 = bs.read("2H") palSize, Null = bs.read("2I") palStart = bs.tell() + bs.readInt() bs.seek(palStart, NOESEEK_ABS) palData = [] for a in range(0, palSize // 4): pR, pG, pB, pA = bs.read("4B") if pR == 0 and pG == 255 and pB == 0 and pA == 255: pG = 0 pA = 0 palData.append(pR) palData.append(pG) palData.append(pB) palData.append(pA) palData = struct.pack("<" + 'B'*len(palData), *palData) if texType == 5: pix = rapi.imageUntwiddlePSP(texData, pixWidth, pixHeight, 8) pix = rapi.imageDecodeRawPal(pix, palData, pixWidth, pixHeight, 8, "r8g8b8a8") elif texType == 4: pix = rapi.imageUntwiddlePSP(texData, pixWidth, pixHeight, 4) pix = rapi.imageDecodeRawPal(pix, palData, pixWidth, pixHeight, 4, "r8g8b8a8") texList.append(NoeTexture(texInfo[i][0], pixWidth, pixHeight, pix, noesis.NOESISTEX_RGBA32)) matList = [] bs.seek(matOffset, NOESEEK_ABS) for i in range(0, matCount): matName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") bs.readBytes(0xC) texID = bs.readInt() unk01, unk02, unk03, unk04 = bs.read("4B") bs.readBytes(0x8) material = NoeMaterial(matName, "") if texID >= 0: material.setTexture(texInfo[texID][0]) #material.setOpacityTexture(texInfo[texID][0]) matList.append(material) meshList = [] bs.seek(meshOffset, NOESEEK_ABS) for i in range(0, meshCount): meshName = bs.readBytes(0x20).decode("ASCII").rstrip("\0") mshCount = bs.readInt() unk11 = bs.readInt() meshStart = bs.tell() + bs.readInt() bs.readBytes(0xC) meshList.append([meshName, meshStart, mshCount, unk11]) #print(meshList) for a in range(0, len(meshList)): mshInfo = [] #print(meshList[a][0]) bs.seek(meshList[a][1], NOESEEK_ABS) for b in range(0, meshList[a][2]): unk20 = bs.readInt() matID = bs.readInt() mshC = bs.readInt() MshOff = bs.tell() + bs.readInt() mshInfo.append([matID, mshC, MshOff]) #print(mshInfo) mshInfo2 = [] for b in range(0, len(mshInfo)): bs.seek(mshInfo[b][2], NOESEEK_ABS) for c in range(0, mshInfo[b][1]): meshPc = bs.readInt() vType = bs.readInt() meshPc2 = bs.readInt() mshPo = bs.tell() + bs.readInt() mshPo2 = bs.tell() + bs.readInt() mshInfo2.append([meshPc, vType, meshPc2, mshPo, mshPo2, matList[(mshInfo[b][0])].name]) #print(mshInfo2) for b in range(0, len(mshInfo2)): mshInfo3 = [] rapi.rpgSetMaterial(mshInfo2[b][5]) bs.seek(mshInfo2[b][3], NOESEEK_ABS) idxList = [[0, 0, 0, 0, 0, 0, 0, 0]] for c in range(0, mshInfo2[b][2]): idxList[0][c] = bs.readInt() bs.seek(mshInfo2[b][4], NOESEEK_ABS) #print(idxList) for c in range(0, mshInfo2[b][0]): mshId2 = bs.readInt() vertCount = bs.readInt() vertStart = bs.tell() + bs.readInt() mshInfo3.append([mshId2, vertCount, vertStart]) #print(mshInfo3) for c in range(0, len(mshInfo3)): #print(mshInfo3[c]) bs.seek(mshInfo3[c][2], NOESEEK_ABS) rapi.rpgSetName(meshList[a][0]) #rapi.rpgSetName(meshList[a][0] + "_" + str(b) + "_" + str(c) + "_" + str(mshInfo2[b][1])) vertStride = 0 if mshInfo2[b][1] == 7: vertStride = 0x18 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0xC) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x8, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0) elif mshInfo2[b][1] == 24: vertStride = 0x1C vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0xC, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x4) elif mshInfo2[b][1] == 25: vertStride = 0x1C vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0xC, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x4) elif mshInfo2[b][1] == 26: vertStride = 0x20 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x14) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x10, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x8) elif mshInfo2[b][1] == 27: vertStride = 0x20 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x14) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x10, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x8) elif mshInfo2[b][1] == 28: vertStride = 0x24 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x18) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x14, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0xC) elif mshInfo2[b][1] == 29: vertStride = 0x24 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x18) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x14, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0xC) elif mshInfo2[b][1] == 30: vertStride = 0x28 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x1C) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x18, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) elif mshInfo2[b][1] == 23: vertStride = 0x28 vertBuff = bs.readBytes(mshInfo3[c][1] * vertStride) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x1C) rapi.rpgBindColorBufferOfs(vertBuff, noesis.RPGEODATA_UBYTE, vertStride, 0x18, 4) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, vertStride, 0x10) else: print(bs.tell()) print("unknown found " + str(mshInfo2[b][1])) vs = NoeBitStream(vertBuff) tmp = [] tmp2 = [] weight = [] index = [] if vertStride == 0x18: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] index.append(idxList[0][0]); index.append(idxList[0][1]); index.append(idxList[0][2]); index.append(idxList[0][3]) index.append(idxList[0][4]); index.append(idxList[0][5]); index.append(idxList[0][6]); index.append(idxList[0][7]) weight.append(w1); weight.append(w2); weight.append(w3); weight.append(w4); weight.append(w5); weight.append(w6); weight.append(w7); weight.append(w8) vs.readBytes(0xC) tmp.append([vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x1C: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] index.append(idxList[0][0]); index.append(idxList[0][1]); index.append(idxList[0][2]); index.append(idxList[0][3]) index.append(idxList[0][4]); index.append(idxList[0][5]); index.append(idxList[0][6]); index.append(idxList[0][7]) weight.append(w1); weight.append(w2); weight.append(w3); weight.append(w4); weight.append(w5); weight.append(w6); weight.append(w7); weight.append(w8) vs.readBytes(0xC) tmp.append([vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x20: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, 0.0, 0.0, 0.0, 0.0] index.append(idxList[0][0]); index.append(idxList[0][1]); index.append(idxList[0][2]); index.append(idxList[0][3]) index.append(idxList[0][4]); index.append(idxList[0][5]); index.append(idxList[0][6]); index.append(idxList[0][7]) weight.append(w1); weight.append(w2); weight.append(w3); weight.append(w4); weight.append(w5); weight.append(w6); weight.append(w7); weight.append(w8) vs.readBytes(0xC) tmp.append([vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x24: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, 0.0, 0.0] index.append(idxList[0][0]); index.append(idxList[0][1]); index.append(idxList[0][2]); index.append(idxList[0][3]) index.append(idxList[0][4]); index.append(idxList[0][5]); index.append(idxList[0][6]); index.append(idxList[0][7]) weight.append(w1); weight.append(w2); weight.append(w3); weight.append(w4); weight.append(w5); weight.append(w6); weight.append(w7); weight.append(w8) vs.readBytes(0xC) tmp.append([vs.readUInt(), vs.readUInt(), vs.readUInt()]) elif vertStride == 0x28: for d in range(0, mshInfo3[c][1]): w1, w2, w3, w4, w5, w6, w7, w8 = [vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF, vs.readUShort() / 0x7FFF] index.append(idxList[0][0]); index.append(idxList[0][1]); index.append(idxList[0][2]); index.append(idxList[0][3]) index.append(idxList[0][4]); index.append(idxList[0][5]); index.append(idxList[0][6]); index.append(idxList[0][7]) weight.append(w1); weight.append(w2); weight.append(w3); weight.append(w4); weight.append(w5); weight.append(w6); weight.append(w7); weight.append(w8) vs.readBytes(0xC) tmp.append([vs.readUInt(), vs.readUInt(), vs.readUInt()]) indexBuff = struct.pack('B'*len(index), *index) weightBuff = struct.pack('f'*len(weight), *weight) rapi.rpgBindBoneIndexBuffer(indexBuff, noesis.RPGEODATA_BYTE, 8, 8) rapi.rpgBindBoneWeightBuffer(weightBuff, noesis.RPGEODATA_FLOAT, 0x20, 8) flip = 0 step = 1 if mshInfo3[c][0] == 0: step = 3 for d in range(0, mshInfo3[c][1] - 2, step): if (tmp[d] != tmp[(d + 1)]) and (tmp[d] != tmp[(d + 2)]) and (tmp[d + 1] != tmp[(d + 2)]): tmp2.append(d) tmp2.append(d + 1 + flip) tmp2.append(d + 2 - flip) if mshInfo3[c][0] != 0: flip = 1 - flip else: flip = 0 #print(d) faceBuff = struct.pack('H'*len(tmp2), *tmp2) if len(faceBuff) > 3: rapi.rpgCommitTriangles(faceBuff, noesis.RPGEODATA_USHORT, len(tmp2), noesis.RPGEO_TRIANGLE, 1) rapi.rpgClearBufferBinds() mdl = rapi.rpgConstructModel() mdl.setModelMaterials(NoeModelMaterials(texList, matList)) mdlList.append(mdl) mdl.setBones(boneList) return 1