-
Notifications
You must be signed in to change notification settings - Fork 4
/
VertexSection.py
75 lines (63 loc) · 2.05 KB
/
VertexSection.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
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",
}
import struct
from . import VS
def parse(file, numVertices, groups):
#print("parsing "+repr(numVertices)+" vertices...")
vertices = []
g = 0
for i in range(0, numVertices):
if i >= groups[g].numVertices:
g = g + 1
vertex = Vertex()
vertex.group = groups[g]
vertex.bone = vertex.group.bone
vertex.feed(file, i)
vertex.x -= vertex.bone.decalage() # hack for translating bones
#print(vertex)
vertices.append(vertex)
return vertices
class Vertex:
def __init__(self):
self.group = None
self.bone = None
self.x = 0
self.y = 0
self.z = 0
self.w = 0 # always 00
self.index = -1
def __repr__(self):
return "(VERTEX : " + " index = "+ repr(self.index)+ " [x:"+ repr(self.x)+ ", y:"+ repr(self.y)+ ", z:"+ repr(self.z)+ ", w:"+ repr(self.w)+ "] )"
def feed(self, file, i):
self.index = i
self.x, self.y, self.z, self.w = struct.unpack("4h", file.read(8))
def tobin(self):
return struct.pack("4h", self.x, self.y, self.z, self.w)
def binsize(self):
return 8
def setGXYZ(self, _g, _x, _y, _z):
self.group = _g
self.x = _x
self.y = _y
self.z = _z
return self
def reverse(self):
self.x = -self.x
self.y = -self.y
self.z = -self.z
def swapYnZ(self):
_y = self.y
_z = -self.z
self.y = _z
self.z = _y
def vector(self):
return (self.x / VS.VERTEX_RATIO, self.y / VS.VERTEX_RATIO, self.z / VS.VERTEX_RATIO)
def blenderSwaped(self):
return (self.x / VS.VERTEX_RATIO, self.z / VS.VERTEX_RATIO, -self.y / VS.VERTEX_RATIO)