-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBoneSection.py
92 lines (80 loc) · 2.66 KB
/
BoneSection.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
bl_info = {
"name": "Vagrant Story file formats Add-on",
"description": "Import-Export Vagrant Story file formats (WEP, SHP, SEQ, ZUD, MPD, ZND, P, FBT, FBC).",
"author": "Sigfrid Korobetski (LunaticChimera)",
"version": (2, 12),
"blender": (3, 2, 0),
"location": "File > Import-Export",
"category": "Import-Export",
}
# https://docs.blender.org/api/current/bpy.types.Bone.html
# used in WEP, SHP and ZUD
import struct
def parse(file, numBones):
#print("parsing "+repr(numBones)+" bones...")
bones = []
for i in range(0, numBones):
bone = Bone()
bone.feed(file, i)
# in theory parent bone are defined before
if bone.parentIndex < numBones:
bone.parent = bones[bone.parentIndex]
#print(bone)
bones.append(bone)
return bones
class Bone:
def __init__(self):
self.index = 0
self.name = "bone"
self.length = 0
self.parent = None
self.parentIndex = -1
self.parentName = None
self.group = None
self.groupId = 0
self.mountId = 0
self.bodyPartId = 0
self.mode = 0
self.unk = (0, 0, 0)
def __repr__(self):
return ("(BONE : "+ " index = "+ repr(self.index)+ " length = "+ repr(self.length)+ " parentIndex = "+ repr(self.parentIndex)
+ " groupId :"+ repr(self.groupId)+ " mountId :"+ repr(self.mountId)+ " bodyPartId :"+ repr(self.bodyPartId)
+ " mode = "+ repr(self.mode)+ " unk = "+ repr(self.unk)+ ")"
)
# for creating a root bone
def defaultBones(self):
self.index = 0
self.length = 0
self.parentIndex = 47
self.groupId = 255
self.mountId = 0
self.bodyPartId = 0
self.mode = 0
self.unk = (0, 0, 0)
def feed(self, file, i):
self.index = i
self.name = "bone_" + str(i)
self.length, self.parentIndex, self.groupId, self.mountId, self.bodyPartId, self.mode = struct.unpack("i 5b", file.read(9))
self.unk = struct.unpack("3B", file.read(3))
file.seek(4, 1) # padding
#self.length = -self.length # positive length
def decalage(self):
if self.parent != None:
return self.parent.length + self.parent.decalage()
else:
return 0
# repacking for export
def tobin(self):
return struct.pack(
"i 12B",
self.length,
self.parentIndex,
self.groupId,
self.mountId,
self.bodyPartId,
self.mode,
self.unk[0], self.unk[1], self.unk[2],
0, 0, 0, 0,
)
def binsize(self):
return 16