then loadPairedFile was coming into mind.
worked perfectly thanks for that.
just one more issue i could some help with,
bindings the weights to skeleton/mesh - i dont understand the syntax that is needed:
Code: Select all
from os.path import *
from math import *
from inc_noesis import *
def registerNoesisTypes():
handle = noesis.register("Warhammer Total War 2", ".anim;.rigid_model_v2")
noesis.setHandlerTypeCheck(handle, noepyCheckType)
noesis.setHandlerLoadModel(handle, noepyLoadModel)
# noesis.setHandlerWriteModel(handle, noepyWriteModel)
# noesis.setHandlerWriteAnim(handle, noepyWriteAnim)
noesis.logPopup()
return 1
def noepyCheckType(data):
'''Verify that the format is supported by this plugin. Default yes'''
return 1
#load the skeleton data
def Skeleton(data):
bs = NoeBitStream(data, NOE_LITTLEENDIAN)
bs.seek(12,0)
SkelNameSize = bs.readShort()
SkelName = bs.readString()
print(SkelName)
bs.seek(-1,1) # for some reason read string is reading 1 byte extra
Check = bs.readUInt()
print(Check)
if Check == 0:
bs.seek(4,1)
if Check != 0:
bs.seek(0,1)
BoneCount = bs.readUInt()
print(BoneCount)
parent_arr = []
BoneNameArray = []
for i in range(BoneCount):
BNameSize = bs.readShort()
BoneName = noeStrFromBytes(bs.readBytes(BNameSize), "ASCII")
BoneParent = bs.readInt()
parent_arr.append(BoneParent) #parr in maxscript
BoneNameArray.append(BoneName)
BMapArray = []
bones = []
for i in range(BoneCount):
BoneId = bs.readUInt() + 1 # need t ocheck if i need this + 1
BMapArray.append(BoneId)
#dont think i need this
for i in range(BoneCount):
BoneId = bs.readUInt()
if Check == 0:
bs.seek(8,1)
#dont think i need this, can skip?
BoneCount1 = bs.readInt()
BoneCount2 = bs.readInt()
Count = bs.readInt()
translation_arr = []
rotation_arr = []
Quat = [0]*4
for i in range(BoneCount):
Tran = NoeVec3.fromBytes(bs.readBytes(12))
translation_arr.append(Tran) # in maxscript * 100 to make bigger
#print(translation_arr)
for i in range(BoneCount):
#a = bs.tell()
#print(a)
b11 = bs.readShort()
b12 = bs.readShort()
b13 = bs.readShort()
b14 = bs.readShort()
#print("b14 = ", b14)
Rot = NoeQuat((b11,b12,b13,b14))
#print("Rot = ", Rot)
Rot = Rot.normalize()
boneMat = Rot.toMat43(transposed = 1)
boneMat[3] = translation_arr[i]
#print("Norm = ", Rot)
#print("boneMat = ", boneMat)
bones.append( NoeBone(i, BoneNameArray[i], boneMat, None, parent_arr[i]) )
# Converting local matrix to world space
for i in range(0, BoneCount):
j = bones[i].parentIndex
#print("j = ", j)
if j != -1:
bones[i].setMatrix(bones[i].getMatrix().__mul__(bones[j].getMatrix()))
return bones
#load mesh data
def Mesh(data):
weights = []
boneids = []
f = NoeBitStream(data, NOE_LITTLEENDIAN)
EndPos = len(data)
Magic = noeStrFromBytes(f.readBytes(4), "ASCII")
print(Magic)
if Magic != "RMV2":
print("worng file format")
MeshCount = f.readInt()
LodCount = f.readInt()
f.seek(140,0) # seek 0x8c from start of file
for i in range(LodCount):
f.seek(28,1)
Pos = f.tell()
j = 0
s = 0
# get vertex, weight, uv data
#read first mesh for now
while s < (MeshCount + LodCount): # read until end of file
id = f.readUInt() # I read unsigned int
LodStart = f.readUInt()
VertexStart = f.readUInt()
VertexCount = f.readUInt()
FaceStart = f.readUInt()
FaceCount = f.readUInt() # facecount/3
print("face count = ",FaceCount/3)
print("VertexCount = ",VertexCount)
print("\n")
#can skip following data need to (seek 24,1)
BBX1 = f.readFloat()
BBY1 = f.readFloat()
BBZ1 = f.readFloat()
BBX2 = f.readFloat()
BBY2 = f.readFloat()
BBZ2 = f.readFloat()
MatType = f.readString() # read string of unknown size - need to check might need seek -1
Unk1 = f.readFloat()
Unk2 = f.readFloat()
f.seek(12,1)
Vtype = f.readShort() # h read short
ModelName = noeStrFromBytes(f.readBytes(32), "ASCII") # read string of known size
MaterialName = noeStrFromBytes(f.readBytes(514), "ASCII")
for i in range(0,3):
f.seek(52,1)
FFFF = f.readInt64() # read long long
BoneCount = f.readUInt()
MatsCount = f.readUInt()
f.seek(8,1)
Unk4 = f.readUInt()
f.seek(128,1)
for i in range(0,BoneCount):
f.seek(84,1)
for i in range(0,MatsCount):
f.seek(260,1)
Unk4 = f.readUInt()
LODCount = f.readUInt()
PosV = f.tell()
#get weight data
if Vtype == 4:
for i in range(VertexCount):
weights.append([])
boneids.append([])
f.seek(8,1)
bone1 = f.readUByte()
bone2 = f.readUByte()
bone3 = f.readUByte()
bone4 = f.readUByte()
weight1 = f.readUByte()
weight2 = f.readUByte()
weight3 = f.readUByte()
weight4 = f.readUByte()
f.seek(16,1)
maxweight = 0
if weight1 != 0:
maxweight = maxweight + weight1
if weight2 != 0:
maxweight = maxweight + weight2
if weight3 != 0:
maxweight = maxweight + weight3
if weight4 != 0:
maxweight = maxweight + weight4
if maxweight != 0 and weight1 != 0:
w1 = float(weight1)
boneids[j].append(bone1)
weights[j].append(w1/255.0)
if maxweight != 0 and weight2 != 0 :
w2 = float(weight2)
boneids[j].append(bone2)
weights[j].append(w2/255.0)
if maxweight != 0 and weight3 != 0:
w3 = float(weight3)
boneids[j].append(bone3)
weights[j].append(w3/255.0)
if maxweight != 0 and weight4 != 0:
w4 = float(weight4)
boneids[j].append(bone4)
weights[j].append(w4/255.0)
if Vtype == 3:
for i in range(VertexCount):
weights.append([])
boneids.append([])
f.seek(8,1)
bone1 = f.readUByte()
bone2 = f.readUByte()
weight1 = f.readUByte()
weight2 = 1 - (weight1/255.0)
#print(weight1)
f.seek(17,1)
maxweight = 0
if weight1 != 0:
maxweight = maxweight + weight1
if weight2 != 0:
maxweight = maxweight + weight2
if maxweight != 0 and weight1 != 0:
w1 = float(weight1)
boneids[j].append(bone1)
weights[j].append(w1/255.0)
if maxweight != 0 and weight2 != 0 :
w2 = float(weight2)
boneids[j].append(bone2)
weights[j].append(w2)
# go back to start of vertex block
f.seek(PosV,0)
print(Vtype)
if Vtype == 4:
VertBuff = f.readBytes(VertexCount * 32)
rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT, 32, 0) # vertex
rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT, 32, 20) # uv
#rapi.rpgBindBoneIndexBuffer(VertBuff, noesis.RPGEODATA_INT, 4*boneids[j], weights[j])
#rapi.rpgBindBoneWeightBuffer(VertBuff, noesis.RPGEODATA_FLOAT, len(weights[j]), weights[j])
if Vtype == 3:
VertBuff = f.readBytes(VertexCount * 28)
rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT, 28, 0)
rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT, 28, 16)
#rapi.rpgBindBoneIndexBuffer(VertBuff, noesis.RPGEODATA_INT, 4*fw.weightsPerVert, fw.weightsPerVert)
#rapi.rpgBindBoneWeightBuffer(VertBuff, noesis.RPGEODATA_FLOAT, 4*fw.weightsPerVert, fw.weightsPerVert)
FaceBuff = f.readBytes(FaceCount * 2)
#rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, VertexCount, noesis.RPGEO_POINTS, 1)
rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount, noesis.RPGEO_TRIANGLE, 1)
s += 1
def noepyLoadModel(data, mdlList):
ctx = rapi.rpgCreateContext()
filePath = rapi.getInputName() # get file path
#fileExt = filePath.split('.')[-1] # get file extesion
skel_data = rapi.loadPairedFile("template - 1", ".anim")
mesh_data = rapi.loadPairedFile("template - 2", ".rigid_model_v2")
bones = Skeleton(skel_data) # get skeleton data
Mesh(mesh_data) # get mesh data
mdl = rapi.rpgConstructModel()
#when i want to load only skeleton
#mdl = NoeModel()
mdl.setBones(bones)
mdlList.append(mdl)
rapi.rpgClearBufferBinds()
return 1
i found in a script the following lines to bind verts to bone by i dont understand what goes in every part (1%,2%,3% etc..) :
rapi.rpgBindBoneIndexBuffer(VertBuff, noesis.RPGEODATA_INT, 1%, 2%)
rapi.rpgBindBoneWeightBuffer(VertBuff, noesis.RPGEODATA_FLOAT, 3%, 4%)
currently i have boneids[] and coresponding weights[] arrays
thanks in advance for you help
heres a smaple of the .anim file used:
https://drive.google.com/open?id=1Jm1Ox ... XrgDnLAPOG
on the bright side i got my size issue fixed
Capture.JPG
You do not have the required permissions to view the files attached to this post.