Currently, I am trying to reshape the weighting data to create Buffers for rpgBindBoneIndexBuffer and rpgBindBoneWeightBuffer., since the file structure looks like figures no.1 while the functions require the figure no. 2. Honestly, I am in trouble with this step since I do not know much about Python. Do you have any hints for this, or we should have another method that get rid of rpgBindBoneIndexBuffer and rpgBindBoneWeightBuffer. Thanks.
here is a working code with weights applied correctly - tested it in 3ds max, and i am using NoeMesh() and NoeModel() so you can learn how to use them
Code: Select all
from os.path import *
from math import *
from inc_noesis import *
class FileData:
def __init__(self):
self.BoneID = []
self.Weights = []
def registerNoesisTypes():
handle = noesis.register("unk game", ".ksw")
noesis.setHandlerTypeCheck(handle, noepyCheckType)
noesis.setHandlerLoadModel(handle, noepyLoadModel)
#opens debug consle
#noesis.logPopup()
return 1
def noepyCheckType(data):
'''Verify that the format is supported by this plugin. Default yes'''
#I preform my check while reading mesh data
return 1
def noepyLoadModel(data, mdlList):
meshName = "test"
Positions = []
Normals = []
UV = []
PolygonIndex = []
meshes = []
VertData = []
bs = NoeBitStream(data, NOE_LITTLEENDIAN)
bs.seek(140,0)
numMesh = bs.readInt()
print("numMesh",numMesh)
numVerts = bs.readInt()
print("numVerts",numVerts)
numFace = bs.readInt()
print("numFace",numFace)
unk1 = bs.readInt()
vertOff = bs.readInt()
normOff = bs.readInt()
unk2 = bs.readInt()
UVOff = bs.readInt()
unk3 = bs.readInt()
unk4 = bs.readInt()
faceoff = bs.readInt()
unk5 = bs.readInt()
boneOff = bs.readInt()
print("boneOff",boneOff)
bs.seek(vertOff,0)
for i in range(numVerts):
vx = bs.readFloat()
vy = bs.readFloat()
vz = bs.readFloat()
VertData.append(FileData())
Positions.append(NoeVec3([vx,vy,vz]))
bs.seek(normOff,0)
for i in range(numVerts):
nx = bs.readFloat()
ny = bs.readFloat()
nz = bs.readFloat()
#print(str(nx ) + str(ny ) + str(nz))
Normals.append(NoeVec3([nx,ny,nz]))
bs.seek(UVOff,0)
for i in range(numVerts):
tu = bs.readFloat()
tv = bs.readFloat()
UV.append(NoeVec3([tu,tv,0.0]))
bs.seek(faceoff,0)
for j in range(numFace*3):
PolygonIndex.append(bs.readInt())
boneList = []
bs.seek(boneOff,0)
boneCount = bs.readUInt()
# read bones loop
for i in range(boneCount):
# read bone name
boneName = bs.readBytes(30).decode('utf-8', 'ignore').replace('\x00','').replace('\xCD','')
# read parent name of the current bone
parentBoneName = bs.readBytes(30).decode('utf-8', 'ignore').replace('\x00','').replace('\xCD','')
# read the number of child bone
numChildren = bs.readUInt()
# read child bone name
for j in range(numChildren):
childBoneName = bs.readBytes(30).decode('utf-8', 'ignore').replace('\x00','').replace('\xCD','')
# read 4x4 bone matrix
boneMat = NoeMat44.fromBytes( bs.readBytes(0x40), NOE_LITTLEENDIAN )
# convert and inverse to 4x3 matrix
boneMat43 = boneMat.toMat43().inverse()
# read 4x4 parent bone matrix
parentMat = NoeMat44.fromBytes( bs.readBytes(0x40), NOE_LITTLEENDIAN )
# convert and inverse to 4x3 matrix
parentMat43 = parentMat.toMat43().inverse()
# read the number of vertices deformed by this bone
numVertices = bs.readUInt()
if numVertices > 0:
weightList = []
VertexList = []
weights = []
# read vertex IDs
for j in range(numVertices):
vertexID = bs.readUInt()
VertData[vertexID].BoneID.append(i)
VertexList.append(vertexID)
# read weights correspondent to vertex IDs
for j in range(numVertices):
weight = bs.readFloat()
VertData[VertexList[j]].Weights.append(weight)
weights.append(weight)
# set bones for Noesis to display
boneList.append(NoeBone(i, boneName, boneMat43, parentBoneName, parentIndex = -1))
for k in range(numVerts):
weightList.append(NoeVertWeight(VertData[k].BoneID, VertData[k].Weights))
a = len(weightList)
print("len weight =", a)
mesh = NoeMesh(PolygonIndex, Positions, meshName)
mesh.setWeights(weightList)
mesh.setNormals(Normals)
mesh.setUVs(UV)
meshes.append(mesh)
mdl = NoeModel(meshes)
mdl.setBones(boneList)
mdlList.append(mdl)
return 1