Recently i started write python script for noesis. For base i used Dark Souls 2 .flv importer and stripped things i don't want.
Well in the end it works but there's left one problem. I have defined mesh count but noesis output it everytime as single mesh. Means there are like 10 meshes but noesis output it as single one.
Has anyone any clue what can cause that? I also left noesis.logPopup() eneabled so you can see how many meshes are in file + vert off and face off.
Here is script:
Code: Select all
from inc_noesis import *
import noesis
import rapi
import os
def registerNoesisTypes():
handle = noesis.register("Renderware Mesh", ".dat")
noesis.setHandlerTypeCheck(handle, noepyCheckType)
noesis.setHandlerLoadModel(handle, noepyLoadModel)
noesis.logPopup()
return 1
def noepyCheckType(data):
bs = NoeBitStream(data)
if len(data) < 20:
return 0
bs.seek(0x10, NOESEEK_REL) #Seek MAGIC
if bs.readUInt() != 0xB8000000:
return 0
return 1
def noepyLoadModel(data, mdlList):
FilePath = rapi.getDirForFilePath(rapi.getInputName())
BaseFileName = rapi.getExtensionlessName(rapi.getLocalFileName(rapi.getInputName()))
ctx = rapi.rpgCreateContext()
class rw_mesh(object):
def __init__(self):
self.numFaceGroups = 0
self.numIndices = []
self.idxOffsets = []
self.idxBuffs = [] #one mesh may have multiple parts
self.numVerts = 0
self.vertSize = 0
self.vertOfs = 0
self.faceOfs = 0
self.vertSectionSize = 0
self.vertBuff = bytes()
self.uvBuff = bytes()
class Parser(object):
def __init__(self, data):
self.inFile = NoeBitStream(data)
self.meshList = []
def build_meshes(self):
for mesh in self.meshList:
if mesh.vertSize == 24:
rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 0)
rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 16)
elif mesh.vertSize == 28:
rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 0)
rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 12)
elif mesh.vertSize == 32:
rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 0)
rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 24)
elif mesh.vertSize == 36:
rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 0)
rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, mesh.vertSize, 28)
for i in range(mesh.numFaceGroups):
numIdx = mesh.numIndices[i]
idxBuff = mesh.idxBuffs[i]
rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_SHORT, numIdx, noesis.RPGEO_TRIANGLE_STRIP, 1)
def get_indices(self, numIdx):
return self.inFile.readBytes(numIdx*2)
def parse_faces(self):
for mesh in self.meshList:
for i in range(mesh.numFaceGroups):
numIdx = mesh.numIndices[i]
idxOfs = mesh.idxOffsets[i]
self.inFile.seek(idxOfs)
idxBuff = self.get_indices(numIdx)
mesh.idxBuffs.append(idxBuff)
def parse_vertices(self):
for mesh in self.meshList:
self.inFile.seek(mesh.vertOfs)
mesh.vertBuff = self.inFile.readBytes(mesh.vertSectionSize)
def parse_face_info(self):
for mesh in self.meshList:
self.inFile.seek(mesh.faceOfs)
for i in range(mesh.numFaceGroups):
FaceInfoBaseOff = self.inFile.tell()
self.inFile.read(36)
numIdx = self.inFile.readUInt()
idxOfs = self.inFile.readUInt() + FaceInfoBaseOff
Null = self.inFile.readUInt()
mesh.numIndices.append(numIdx)
mesh.idxOffsets.append(idxOfs)
print("Face Data Offset",idxOfs)
def parse_vertex_info(self):
for mesh in self.meshList:
VertexInfoBaseOff = self.inFile.tell()
numVerts = self.inFile.readUInt()
vertOfs = self.inFile.readUInt() + VertexInfoBaseOff
sectionSize = self.inFile.readUInt()
faceOfs = self.inFile.readUInt() + VertexInfoBaseOff
numFaceGroups = self.inFile.readUInt()
vertSize = self.inFile.readUInt()
VTXFlag2 = self.inFile.readUInt()
mesh.numVerts = numVerts
mesh.vertSize = vertSize
mesh.vertOfs = vertOfs
mesh.vertSectionSize = sectionSize
mesh.faceOfs = faceOfs
mesh.numFaceGroups = numFaceGroups
print("Vertex Data Offset",vertOfs)
def parse_file(self):
Value0 = self.inFile.readFloat()
Value1 = self.inFile.readFloat()
Value2 = self.inFile.readFloat()
Value3 = self.inFile.readFloat()
File_ID = self.inFile.readBytes(4)
File_SID = self.inFile.readUInt()
Flag = self.inFile.readUInt()
VertexMainInfoOff = self.inFile.readUInt()
Table0Off = self.inFile.readUInt()
numMesh = self.inFile.readUInt()
print("\nMesh Count",numMesh)
self.inFile.seek(0x10, NOESEEK_REL) # Skip something
Table3Off = self.inFile.readUInt()
Table3Size = self.inFile.readUInt()
Table4Off = self.inFile.readUInt()
Table4Size = self.inFile.readUInt()
Table1Off = self.inFile.readUInt()
MaterialInfoOff = self.inFile.readUInt()
MaterialCnt = self.inFile.readUInt()
PosRotInfoOff = self.inFile.readUInt()
UnkData0Off = self.inFile.readUInt()
PosRotInfoCnt = self.inFile.readUInt()
UnkData1Off = self.inFile.readUInt()
Table2Off = self.inFile.readUInt()
Count0 = self.inFile.readUByte()
Count1 = self.inFile.readUByte()
Count2 = self.inFile.readUByte()
Count3 = self.inFile.readUByte()
Null = self.inFile.readUInt() # Header end
for i in range(numMesh):
mesh = rw_mesh()
self.meshList.append(mesh)
self.inFile.seek(VertexMainInfoOff)
self.parse_vertex_info()
self.parse_face_info()
self.parse_vertices()
self.parse_faces()
self.build_meshes()
parser = Parser(data)
parser.parse_file()
mdl = rapi.rpgConstructModel()
mdlList.append(mdl)
rapi.rpgClearBufferBinds()
return 1
As you can see on image "boxes.dat 1/1" instead of "boxes.dat 1/10"
Thanks in advance!
EDiT: Found something related to mesh name.
rapi.rpgSetName(meshName)
meshName must be read as string
But how to get file name without extension and add prefix _num++ to it?
EDiT1: Thanks you for your time but i solved it. It was by rapid.rpg Set Name(mesh Name) which i must added. Now i can see all that meshes separated