forked from Durik256/Noesis-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt_3dc.py
105 lines (83 loc) · 3.36 KB
/
fmt_3dc.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#by Durik256 15.03.2022 for xentax
from inc_noesis import *
def registerNoesisTypes():
handle = noesis.register("Shaiya",".3dc")
noesis.setHandlerTypeCheck(handle, CheckType)
noesis.setHandlerLoadModel(handle, LoadModel)
return 1
def CheckType(data):
return 1
def LoadModel(data, mdlList):
bs = NoeBitStream(data)
mdl, bones = ParseFile(bs)
paired_models = findAllFileFromFolder('.3dc')
for model in paired_models:
p_bs = NoeBitStream(rapi.loadIntoByteArray(model))
p_mdl, p_bones = ParseFile(p_bs)
if len(bones) == len(p_bones):
mdl.meshes = mdl.meshes + tuple([p_mdl.meshes[0]])
#anims
animList, animBones = [], []
#animPath = rapi.getDirForFilePath(rapi.getInputName())#+'vi_05_run.ANI'
animPath = noesis.userPrompt(noesis.NOEUSERVAL_FILEPATH, "Open File", "Select animations", noesis.getSelectedFile())
openAnim(animList, animBones, animPath)
if animList and len(bones) == len(animBones[0]):
mdl.setAnims(animList)
fixParent(bones, animBones[0])
mdl.setBones(bones)
mdlList.append(mdl)
rapi.setPreviewOption("setAngOfs", "0 0 90")
return 1
def ParseFile(bs):
unk = bs.readInt()
stride, cWeiht = type(unk)
cBone = bs.readInt()
bones = []
for x in range(cBone):
mat = NoeMat44.fromBytes(bs.readBytes(64)).inverse().toMat43()
bones.append(NoeBone(x,"bone_"+str(x), mat))
cVert = bs.readInt()
vbuf = bs.readBytes(cVert*stride)
cFace = bs.readInt()
ibuf = bs.readBytes(cFace*6)
ctx = rapi.rpgCreateContext()
rapi.rpgBindPositionBuffer(vbuf, noesis.RPGEODATA_FLOAT, stride)
rapi.rpgBindBoneWeightBufferOfs(vbuf, noesis.RPGEODATA_FLOAT, stride, 12, cWeiht)
rapi.rpgBindBoneIndexBufferOfs(vbuf, noesis.RPGEODATA_BYTE, stride, 12+(cWeiht*4), cWeiht)
rapi.rpgBindNormalBufferOfs(vbuf, noesis.RPGEODATA_FLOAT, stride, stride-20)
rapi.rpgBindUV1BufferOfs(vbuf, noesis.RPGEODATA_FLOAT, stride, stride-8)
rapi.rpgCommitTriangles(ibuf, noesis.RPGEODATA_USHORT, cFace*3, noesis.RPGEO_TRIANGLE)
mdl = rapi.rpgConstructModel()
return mdl, bones
def type(unk):
stride, cWeiht = 40, 1
if unk != 0:
stride, cWeiht = 48, 3
return stride, cWeiht
def fixParent(bones, animBones):
print(len(animBones))
for x in range(len(animBones)):
bones[x].parentIndex = animBones[x].parentIndex
def openAnim(animList, animBones, animPath):
sciptPath = rapi.getDirForFilePath(os.path.realpath(__file__))+'fmt_ani.py'
if not animPath:
return 0
if rapi.checkFileExists(sciptPath) and rapi.checkFileExists(animPath):
import fmt_ani
mdlList = []
fmt_ani.LoadModel(rapi.loadIntoByteArray(animPath), mdlList)
if mdlList:
animList.append(mdlList[0].anims[0])
animBones.append(mdlList[0].bones)
def findAllFileFromFolder(ext):
Dir = rapi.getDirForFilePath(rapi.getInputName())
local = rapi.getLocalFileName(rapi.getInputName())
name = local.split('#')[0]
paths = []
if Dir and os.path.exists(Dir):
files = next(os.walk(Dir))[2]
for file in files:
if rapi.checkFileExt(file,ext) and name in file and local != file:
paths.append(os.path.join(Dir,file))
print(paths[-1])
return paths