-
Notifications
You must be signed in to change notification settings - Fork 4
/
fmt_iaa.py
88 lines (77 loc) · 3.19 KB
/
fmt_iaa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#by Durik256
from inc_noesis import *
def registerNoesisTypes():
handle = noesis.register("Esel Studio", ".iaa_mesh")
noesis.setHandlerTypeCheck(handle, noepyCheckType)
noesis.setHandlerLoadModel(handle, noepyLoadModel)
#noesis.logPopup()
return 1
def noepyCheckType(data):
return 1
split_sm = True
def noepyLoadModel(data, mdlList):
bs = NoeBitStream(data)
ctx = rapi.rpgCreateContext()
num_mesh = bs.readUInt()
for mi in range(num_mesh):
print(mi,'>>>>>>>>>>>>>>>>')
cpos = bs.tell()
u0,u1,msize,u2,u3,numSM = bs.read('HHIHHI')
print(u0,u1,msize,u2,u3,numSM)
sm = []
for x in range(numSM):
iofs,inum = bs.read('2I')
sm.append([iofs,inum])
print(x,'iofs:',iofs,'inum:',inum)
vnum, vsize = bs.read('2I')
stride = vsize//vnum
print('vnum:',vnum,'vsize:',vsize,'stride:',stride,'vbuf_start:', bs.tell())
vbuf = bs.read(vsize)
inum, itype, isize = bs.read('3I')
print('inum:',inum,'itype:',itype,'isize:',isize, 'ibuf_start:', bs.tell())
ibuf_ofs = bs.tell()
ibuf = bs.read(isize)
bs.seek(ibuf_ofs + (int(-1 * (isize/4) // 1 * -1)*4))
print('end_ibuf:',bs.tell())
num_attr = bs.readUInt()
rapi.rpgBindPositionBuffer(vbuf, noesis.RPGEODATA_FLOAT, stride)
for x in range(num_attr):
# 0-type(1-vert/5-norm/33-uv); 1-fmt(28-3f/27-2f); 2-ofs; 3-stride
a = bs.read('4I')
print(' ',a)
if a[0] == 1:
#rapi.rpgBindPositionBuffer(vbuf, noesis.RPGEODATA_FLOAT, stride)
pass
elif a[0] == 5:
rapi.rpgBindNormalBufferOfs(vbuf, noesis.RPGEODATA_FLOAT, stride, a[2])
elif a[0] == 33:
rapi.rpgBindUV1BufferOfs(vbuf, noesis.RPGEODATA_FLOAT, stride, a[2])
num_attr = bs.readUInt()
print('end_mesh:',bs.tell())
if split_sm:
for i,x in enumerate(sm):
iofs,inum = x
rapi.rpgSetName('mesh_%i_%i'%(mi,i))
if itype == 3:
bs.seek(ibuf_ofs + iofs*2)
ibuf = bs.read(inum*2)
rapi.rpgCommitTriangles(ibuf,noesis.RPGEODATA_USHORT,inum,noesis.RPGEO_TRIANGLE)
elif itype == 2:
bs.seek(ibuf_ofs + iofs)
ibuf = bs.read(inum)
rapi.rpgCommitTriangles(ibuf,noesis.RPGEODATA_UBYTE,inum,noesis.RPGEO_TRIANGLE)
else:
rapi.rpgSetName('mesh_%i'%mi)
if itype == 3:
rapi.rpgCommitTriangles(ibuf,noesis.RPGEODATA_USHORT,inum,noesis.RPGEO_TRIANGLE)
elif itype == 2:
rapi.rpgCommitTriangles(ibuf,noesis.RPGEODATA_UBYTE,inum,noesis.RPGEO_TRIANGLE)
rapi.rpgClearBufferBinds()
bs.seek(cpos+msize)
try:
mdl = rapi.rpgConstructModel()
except:
mdl = NoeModel()
mdl.setModelMaterials(NoeModelMaterials([], [NoeMaterial('default','')]))
mdlList.append(mdl)
return 1