def __init__(self, boneOffset, weightOffset, stride): if boneSect is None: return self.boneOffset = boneOffset self.weightOffset = weightOffset self.stride = stride self.boneData = [] self.weightData = [] self.collectBones() self.collectWeights() self.mapBones() flatten = lambda l: [ item for sublist in l for item in sublist ] boneBuf = struct.pack("B" * (vxbfEntryCount[i] * 4), *flatten(self.boneData)) rapi.rpgBindBoneIndexBuffer(boneBuf, noesis.RPGEODATA_BYTE, 0x4, 4) weightBuf = struct.pack("f" * (vxbfEntryCount[i] * 4), *flatten(self.weightData)) rapi.rpgBindBoneWeightBuffer(weightBuf, noesis.RPGEODATA_FLOAT, 0x10, 4)
def noepyLoadModel(data, mdlList): bs = NoeBitStream(data) if bs.readInt() != NOEPY_HEADER: return 0 if bs.readInt() != NOEPY_VERSION: return 0 #no need to explicitly free the context (created contexts are auto-freed after the handler), but DO NOT hold any references to it outside of this method ctx = rapi.rpgCreateContext() numMeshes = bs.readInt() for i in range(0, numMeshes): meshName = bs.readString() meshMat = bs.readString() numIdx = bs.readInt() numPos = bs.readInt() numNrm = bs.readInt() numUVs = bs.readInt() numTan = bs.readInt() numClr = bs.readInt() numWeights = bs.readInt() numBoneRefs = bs.readInt() if numBoneRefs > 0: boneMap = bs.read("i" * numBoneRefs) rapi.rpgSetBoneMap(boneMap) #set the bone map rapi.rpgSetName(meshName) rapi.rpgSetMaterial(meshMat) triangles = bs.readBytes(numIdx * 4) positions = bs.readBytes(numPos * 12) normals = bs.readBytes(numPos * 12) if numNrm == numPos else None uvs = bs.readBytes(numPos * 12) if numUVs == numPos else None tans = bs.readBytes(numPos * 48) if numTan == numPos else None colors = bs.readBytes(numPos * 16) if numClr == numPos else None rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindUV1Buffer(uvs, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindColorBuffer(colors, noesis.RPGEODATA_FLOAT, 16, 4) if numWeights > 0: vwList = [] for j in range(0, numWeights): vwNum = bs.readInt() bidx = [] bwgt = [] for k in range(0, vwNum): bidx.append(bs.readInt()) for k in range(0, vwNum): bwgt.append(bs.readFloat()) vwList.append(NoeVertWeight(bidx, bwgt)) fw = NoeFlatWeights(vwList) rapi.rpgBindBoneIndexBuffer(fw.flatW[:fw.weightValOfs], noesis.RPGEODATA_INT, 4 * fw.weightsPerVert, fw.weightsPerVert) rapi.rpgBindBoneWeightBuffer(fw.flatW[fw.weightValOfs:], noesis.RPGEODATA_FLOAT, 4 * fw.weightsPerVert, fw.weightsPerVert) numMorphFrames = bs.readInt() for j in range(0, numMorphFrames): numMFPos = bs.readInt() numMFNrm = bs.readInt() morphPosAr = bs.readBytes(numMFPos * 12) rapi.rpgFeedMorphTargetPositions(morphPosAr, noesis.RPGEODATA_FLOAT, 12) if numMFNrm > 0: morphNrmAr = bs.readBytes(numMFNrm * 12) rapi.rpgFeedMorphTargetNormals(morphNrmAr, noesis.RPGEODATA_FLOAT, 12) rapi.rpgCommitMorphFrame(numMFPos) rapi.rpgCommitMorphFrameSet() rapi.rpgCommitTriangles(triangles, noesis.RPGEODATA_INT, numIdx, noesis.RPGEO_TRIANGLE, 1) rapi.rpgClearBufferBinds( ) #reset in case a subsequent mesh doesn't have the same components mdl = rapi.rpgConstructModel() bones = [] numBones = bs.readInt() for i in range(0, numBones): bone = noepyReadBone(bs) bones.append(bone) anims = [] numAnims = bs.readInt() for i in range(0, numAnims): animName = bs.readString() numAnimBones = bs.readInt() animBones = [] for j in range(0, numAnimBones): animBone = noepyReadBone(bs) animBones.append(animBone) animNumFrames = bs.readInt() animFrameRate = bs.readFloat() numFrameMats = bs.readInt() animFrameMats = [] for j in range(0, numFrameMats): frameMat = NoeMat43.fromBytes(bs.readBytes(48)) animFrameMats.append(frameMat) anim = NoeAnim(animName, animBones, animNumFrames, animFrameMats, animFrameRate) anims.append(anim) mdl.setBones(bones) mdl.setAnims(anims) mdlList.append( mdl) #important, don't forget to put your loaded model in the mdlList return 1
def noepyLoadModel(data, mdlList): LOADANIM = 0 ExportSkin = 1 VertexBool = 0 #Vertex Bool = 1 is Vertex Tint Channel Vertex Bool = 0 is Material Layers #Remember Vertex Colors are BGRA ctx = rapi.rpgCreateContext() bs = NoeBitStream(data) rapi.rpgSetOption(noesis.RPGOPT_MORPH_RELATIVEPOSITIONS, 1) rapi.rpgSetOption(noesis.RPGOPT_MORPH_RELATIVENORMALS, 1) #IDSig = bs.readUInt() #Blank1 = bs.readUInt() #BSphereX = bs.readFloat() #BSphereY = bs.readFloat() #BSphereZ = bs.readFloat() #BSphereThing = bs.readFloat() #UNK1 = bs.readFloat() #BBoxX1 = bs.readFloat() #BBoxY1 = bs.readFloat() #BBoxZ1 = bs.readFloat() #BBoxX2 = bs.readFloat() #BBoxY2 = bs.readFloat() #BBoxZ2 = bs.readFloat() #BBoxScaleX1 = bs.readFloat() #BBoxScaleY1 = bs.readFloat() #BBoxScaleZ1 = bs.readFloat() #BBoxScaleX2 = bs.readFloat() #BBoxScaleY2 = bs.readFloat() #BBoxScaleZ2 = bs.readFloat() #MipConstantUV0 = bs.readFloat() #MipConstantUV1 = bs.readFloat() bs.seek(84, NOESEEK_ABS) posAli = 0 #MTRL STUFF #MatSig = bs.readUInt() MatCount = bs.read("L") MatNames = [] pos = bs.tell() print(MatCount, pos) #MTRL LOOP for i in range(0, MatCount[0]): #MatCharCount = bs.readUInt() #print(MatCharCount) #MatNames.append (bs.readBytes(MatCharCount).decode("ASCII").rstrip("\0")) bs.seek(4, NOESEEK_REL) MatNames.append(bs.readString()) #STBS LOOP print(MatNames) subMeshCount = bs.readUInt() print(subMeshCount) MatID = [] VertCount = [] VertBuffType = [] FaceCount = [] FaceType = [] BoneIDS = [] BIXD = [] BoneIDLOC = [] BoneIDS = [] mdl = [] VertID = [] MorphVertPOS = [] MorphVertNorm = [] MorphFrameCountID = [] MDLWritten = rapi.getInputName() MDLWrite = NoeBitStream() topname = rapi.getExtensionlessName( rapi.getExtensionlessName(rapi.getInputName())) for i in range(0, subMeshCount): BoneIDSPre = [] print("Sub Mesh", i) tsbsSig = bs.readUInt() print(tsbsSig) MatID.append(bs.readUInt()) Blank2 = bs.readUInt() BVXD = bs.readUInt() VertCount.append(bs.readUInt()) VertBuffType.append(bs.readUShort()) print(VertBuffType[i]) MorphFrameCount = bs.readUInt() MorphFrameCountID.append(MorphFrameCount) if MorphFrameCount is 0: print(MorphFrameCount, "Morph Frame Count is 0") if MorphFrameCount is not 0: print(MorphFrameCount, "Morph Frame Count is not 0") n = 0 MorphVertCountList = [] FrameLOC = [] FrameOrder = [] for m in range(0, MorphFrameCount): pos = bs.tell() FrameLOC.append(pos) MorphVertCount = bs.readUInt() MorphVertCountList.append(MorphVertCount) #print("MorphVertCount", MorphVertCount) #n = 0 FrameName = ("Frame_" + str(n)) n = (n + 1) Frame = [] for mv in range(0, MorphVertCount): VertID.append(bs.readUInt()) VertX = bs.readUShort() #pos = bs.tell() #VertX = (VertX / 32767) VertY = bs.readUShort() #pos = bs.tell() #VertY = (VertY / 32767) VertZ = bs.readUShort() #pos = bs.tell() #VertZ = (VertZ / 32767) VertNormX = bs.readUShort() VertNormY = bs.readUShort() VertNormZ = bs.readUShort() bs.seek(8, NOESEEK_REL) #pos = bs.tell() for mc in range(0, MorphFrameCount): FrameOrder.append(bs.readUShort()) FinalMorphCount = bs.readUShort() MorphCharCount = bs.readUInt() MorphName = bs.readString() print(MorphName) if VertBuffType[i] == int(768) or VertBuffType[i] == int(256): bs.seek(3, NOESEEK_REL) pos = bs.tell() BIXD.append(pos) BIXDSig = bs.readUInt() Blank2 = bs.readUInt() FaceCount.append(bs.readUInt()) FaceType.append(bs.readUInt()) pos = bs.tell() BoneIDLOC.append(pos) BoneIDCount = bs.readUByte() for bi in range(0, BoneIDCount): BoneIDSPre.append(bs.readUByte()) BoneIDS.append(BoneIDSPre) bs.seek(56, NOESEEK_REL) if VertBuffType[i] == (1280, ): crap = bs.readUShort() VertBuffType[i] = (1024, ) print("MaterialIDS", MatID) #RigStuff if VertBuffType[0] == int(1024) or VertBuffType[0] == int(768): boneReList = RigStuff(VertBuffType, topname) #MDLSourceStuff MeshExists = rapi.checkFileExists(topname + str(".Mesh")) if MeshExists: MDLFile = rapi.loadIntoByteArray(topname + str(".Mesh")) else: MDLFile = rapi.loadPairedFile("Brutal Legend", ".Mesh") MDL = NoeBitStream(MDLFile) MeshStarts = [] MeshFaceStarts = [] BONINDBUFF = [] #print("MeshStarts", MeshStarts, "MeshFaceStarts", MeshFaceStarts) print("MDL AT ", MDL.tell()) for s in range(0, subMeshCount): Face = [] POS, NORM, TAN, UV1, UV2, COL1, COL2, BI, BW = VertStuff( MDL, VertCount[s], VertBuffType[s]) POS = struct.pack('B' * len(POS), *POS) NORM = struct.pack('B' * len(NORM), *NORM) TAN = struct.pack('B' * len(TAN), *TAN) UV1 = struct.pack('B' * len(UV1), *UV1) UV2 = struct.pack('B' * len(UV2), *UV2) if VertBuffType[s] == int(1024) or VertBuffType[s] == int(512): rapi.rpgBindPositionBuffer(POS, noesis.RPGEODATA_HALFFLOAT, 8) rapi.rpgBindNormalBuffer(NORM, noesis.RPGEODATA_HALFFLOAT, 8) rapi.rpgBindTangentBuffer(TAN, noesis.RPGEODATA_HALFFLOAT, 8) rapi.rpgBindUV1Buffer(UV1, noesis.RPGEODATA_HALFFLOAT, 4) rapi.rpgBindUV2Buffer(UV2, noesis.RPGEODATA_HALFFLOAT, 4) if VertBuffType[s] == int(768) or VertBuffType[s] == int(256): rapi.rpgBindPositionBuffer(POS, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindNormalBuffer(NORM, noesis.RPGEODATA_FLOAT, 12) #rapi.rpgBindTangentBuffer(TAN, noesis.RPGEODATA_FLOAT, 16) rapi.rpgBindUV1Buffer(UV1, noesis.RPGEODATA_FLOAT, 8) rapi.rpgBindUV2Buffer(UV2, noesis.RPGEODATA_FLOAT, 8) if VertexBool: COL = COL2 else: COL = COL1 COL = struct.pack('B' * len(COL), *COL) #VertColor = BGRA rapi.rpgBindColorBuffer(COL, noesis.RPGEODATA_UBYTE, 4, 4) if VertBuffType[s] == int(1024) or VertBuffType[s] == int(768): rapi.rpgSetBoneMap(BoneIDS[s]) IDS = struct.pack('B' * len(BI), *BI) WEIGHTS = struct.pack('B' * len(BW), *BW) if ExportSkin: print("Bind Skin") rapi.rpgBindBoneIndexBuffer(IDS, noesis.RPGEODATA_BYTE, 4, 4) rapi.rpgBindBoneWeightBuffer(WEIGHTS, noesis.RPGEODATA_UBYTE, 4, 4) FaceBuff = MDL.readBytes(FaceCount[s] * 2) # FaceBuff = struct.pack('H'*len(Face), *Face) if MorphFrameCountID[s] is not 0: ## RETURN = bs.tell() for mf in range(0, MorphFrameCountID[s]): bs.seek(FrameLOC[mf], NOESEEK_ABS) # print(FrameLOC[mf], FlexNames[FrameOrder[mf]]) MorphVertCount = bs.readUInt() FramePOS = [] FrameNorm = [] FrameTan = [] FrameIDS = [] MorphPOS = [] MorphNorm = [] MorphTan = [] for mm in range(0, MorphVertCount): FrameIDS.append(bs.readUInt()) MPOSX = (((bs.readShort() / 32767) * 2)) MPOSY = (((bs.readShort() / 32767) * 2)) MPOSZ = (((bs.readShort() / 32767) * 2)) MNORMX = (((bs.readShort() / 32767) * 2)) MNORMY = (((bs.readShort() / 32767) * 2)) MNORMZ = (((bs.readShort() / 32767) * 2)) MTANX = (((bs.readShort() / 32767) * 2)) MTANY = (((bs.readShort() / 32767) * 2)) MTANZ = (((bs.readShort() / 32767) * 2)) MTANW = (((bs.readShort() / 32767) * 2)) FramePOS.append((float(MPOSX), float(MPOSY), float(MPOSZ))) FrameNorm.append( (float(MNORMX), float(MNORMY), float(MNORMZ))) FrameTan.append((float(MTANX), float(MTANY), float(MTANZ), float(MTANW))) for mv in range(0, VertCount[s]): if mv in FrameIDS: ID = FrameIDS.index(mv) MorphPOS.append(FramePOS[ID]) MorphNorm.append(FrameNorm[ID]) MorphTan.append(FrameTan[ID]) else: MorphPOS.append((float(0.0), float(0.0), float(0.0))) MorphNorm.append((float(0.0), float(0.0), float(0.0))) MorphTan.append( (float(0.0), float(0.0), float(0.0), float(0.0))) MPOSBUFF3 = list(itertools.chain.from_iterable(MorphPOS)) MNORMBUFF = list(itertools.chain.from_iterable(MorphNorm)) MTANBUFF = list(itertools.chain.from_iterable(MorphTan)) #rapi.rpgSetName(MeshName) MPOS = struct.pack('f' * len(MPOSBUFF3), *MPOSBUFF3) MNORM = struct.pack('f' * len(MNORMBUFF), *MNORMBUFF) MTAN = struct.pack('f' * len(MTANBUFF), *MTANBUFF) rapi.rpgFeedMorphTargetPositions(MPOS, noesis.RPGEODATA_FLOAT, 12) rapi.rpgFeedMorphTargetNormals(MNORM, noesis.RPGEODATA_FLOAT, 12) rapi.rpgCommitMorphFrame(VertCount[s]) MPOSBUFF = [] MNORMBUFF = [] MTANBUFF = [] MPOS = None MNORM = None MTAN = None rapi.rpgCommitMorphFrameSet() Mesh = ("Mesh_" + str(s)) MeshName = str(Mesh) rapi.rpgSetName(MeshName) print(MatNames[MatID[s]]) CurrentMaterial = MatNames[MatID[s]] CurrentMaterial = CurrentMaterial.replace('/', '_') rapi.rpgSetMaterial(CurrentMaterial) rapi.rpgSmoothTangents() if FaceType[s] == 2: rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount[s], noesis.RPGEO_TRIANGLE, 1) else: rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount[s], noesis.RPGEO_TRIANGLE_STRIP, 1) rapi.rpgClearBufferBinds() mdl = rapi.rpgConstructModel() if LOADANIM == (0): print("No Anim") if VertBuffType[0] == int(1024) or VertBuffType[0] == int(768): mdl.setBones(boneReList) mdlList.append( mdl ) #important, don't forget to put your loaded model in the mdlList return 1
def noepyLoadModel(data, mdlList): bs = NoeBitStream(data) if bs.readInt() != NOEPY_HEADER: return 0 if bs.readInt() != NOEPY_VERSION: return 0 #no need to explicitly free the context (created contexts are auto-freed after the handler), but DO NOT hold any references to it outside of this method ctx = rapi.rpgCreateContext() numMeshes = bs.readInt() for i in range(0, numMeshes): meshName = bs.readString() meshMat = bs.readString() numIdx = bs.readInt() numPos = bs.readInt() numNrm = bs.readInt() numUVs = bs.readInt() numTan = bs.readInt() numClr = bs.readInt() numWeights = bs.readInt() numBoneRefs = bs.readInt() if numBoneRefs > 0: boneMap = bs.read("i"*numBoneRefs) rapi.rpgSetBoneMap(boneMap) #set the bone map rapi.rpgSetName(meshName) rapi.rpgSetMaterial(meshMat) triangles = bs.readBytes(numIdx * 4) positions = bs.readBytes(numPos * 12) normals = bs.readBytes(numPos * 12) if numNrm == numPos else None uvs = bs.readBytes(numPos * 12) if numUVs == numPos else None tans = bs.readBytes(numPos * 48) if numTan == numPos else None colors = bs.readBytes(numPos * 16) if numClr == numPos else None rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindUV1Buffer(uvs, noesis.RPGEODATA_FLOAT, 12) rapi.rpgBindColorBuffer(colors, noesis.RPGEODATA_FLOAT, 16, 4) if numWeights > 0: vwList = [] for j in range(0, numWeights): vwNum = bs.readInt() bidx = [] bwgt = [] for k in range(0, vwNum): bidx.append(bs.readInt()) for k in range(0, vwNum): bwgt.append(bs.readFloat()) vwList.append(NoeVertWeight(bidx, bwgt)) fw = NoeFlatWeights(vwList) rapi.rpgBindBoneIndexBuffer(fw.flatW[:fw.weightValOfs], noesis.RPGEODATA_INT, 4*fw.weightsPerVert, fw.weightsPerVert) rapi.rpgBindBoneWeightBuffer(fw.flatW[fw.weightValOfs:], noesis.RPGEODATA_FLOAT, 4*fw.weightsPerVert, fw.weightsPerVert) numMorphFrames = bs.readInt() for j in range(0, numMorphFrames): numMFPos = bs.readInt() numMFNrm = bs.readInt() morphPosAr = bs.readBytes(numMFPos * 12) rapi.rpgFeedMorphTargetPositions(morphPosAr, noesis.RPGEODATA_FLOAT, 12) if numMFNrm > 0: morphNrmAr = bs.readBytes(numMFNrm * 12) rapi.rpgFeedMorphTargetNormals(morphNrmAr, noesis.RPGEODATA_FLOAT, 12) rapi.rpgCommitMorphFrame(numMFPos) rapi.rpgCommitMorphFrameSet() rapi.rpgCommitTriangles(triangles, noesis.RPGEODATA_INT, numIdx, noesis.RPGEO_TRIANGLE, 1) rapi.rpgClearBufferBinds() #reset in case a subsequent mesh doesn't have the same components mdl = rapi.rpgConstructModel() bones = [] numBones = bs.readInt() for i in range(0, numBones): bone = noepyReadBone(bs) bones.append(bone) anims = [] numAnims = bs.readInt() for i in range(0, numAnims): animName = bs.readString() numAnimBones = bs.readInt() animBones = [] for j in range(0, numAnimBones): animBone = noepyReadBone(bs) animBones.append(animBone) animNumFrames = bs.readInt() animFrameRate = bs.readFloat() numFrameMats = bs.readInt() animFrameMats = [] for j in range(0, numFrameMats): frameMat = NoeMat43.fromBytes(bs.readBytes(48)) animFrameMats.append(frameMat) anim = NoeAnim(animName, animBones, animNumFrames, animFrameMats, animFrameRate) anims.append(anim) mdl.setBones(bones) mdl.setAnims(anims) mdlList.append(mdl) #important, don't forget to put your loaded model in the mdlList return 1
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 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