This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
setReader.py
214 lines (183 loc) · 5.53 KB
/
setReader.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import bpy
from . import fileHelper, common, os
import mathutils
class ObjEntry:
index: int
clippingLvl: int
worldMtx: mathutils.Matrix
var: common.Vector3
def __init__(self,
index: int,
clippingLvl: int,
xRot: int,
yRot: int,
zRot: int,
posx: float,
posy: float,
posz: float,
var1: float,
var2: float,
var3: float):
self.index = index
self.clippingLvl = clippingLvl
self.var = common.Vector3((var1, var2, var3))
xRot = common.BAMSToRad(xRot)
yRot = common.BAMSToRad(yRot)
zRot = common.BAMSToRad(zRot)
posMtx = mathutils.Matrix.Translation((posx, -posz, posy))
rotMtx = mathutils.Euler((xRot, -zRot, yRot), 'XZY').to_matrix().to_4x4()
scale = 1
scaleMtx = common.matrixFromScale((scale,scale,scale))
self.worldMtx = posMtx @ rotMtx @ scaleMtx
def ReadFile(path: str, context, bigEndian: bool, useEntryNum: bool):
fileR = fileHelper.FileReader(path)
fileR.setBigEndian(bigEndian)
objCount = fileR.rUInt(0)
print("objects:", objCount)
objs = list()
for i in range(objCount):
tmpAddr = 0x20 + (i * 0x20)
header = fileR.rUShort(tmpAddr)
objs.append(ObjEntry(
header & 0x0FFF,
(header & 0xF000) >> 0xC,
fileR.rShort(tmpAddr + 0x02),
fileR.rShort(tmpAddr + 0x04),
fileR.rShort(tmpAddr + 0x06),
fileR.rFloat(tmpAddr + 0x08),
fileR.rFloat(tmpAddr + 0x0C),
fileR.rFloat(tmpAddr + 0x10),
fileR.rFloat(tmpAddr + 0x14),
fileR.rFloat(tmpAddr + 0x18),
fileR.rFloat(tmpAddr + 0x1C) ))
cName = os.path.splitext(os.path.basename(path))[0]
col = bpy.data.collections.new("SET_" + cName)
context.scene.collection.children.link(col)
for i, o in enumerate(objs):
#print(str(o))
if (useEntryNum):
name = str(i) + "_SetItem_" + str(o.index)
else:
name = "SetItem_" + str(o.index)
obj = bpy.data.objects.new(name, None)
obj.matrix_world = o.worldMtx
col.objects.link(obj)
class sa1CamEntry:
camType: int
camPriority: int
camAdjType: int
camColType: int
camRotationX: int
camRotationY: int
camPositionX: float
camPositionY: float
camPositionZ: float
camScaleX: float
camScaleY: float
camScaleZ: float
camAngleX: int
camAngleY: int
camPointAx: float
camPointAy: float
camPointAz: float
camPointBx: float
camPointBy: float
camPointBz: float
camVariable: float
camMtx: mathutils.Matrix
camPointAMtx: mathutils.Matrix
camPointBMtx: mathutils.Matrix
def __init__(self,
camType: int,
camPriority: int,
camAdjType: int,
camColType: int,
camRotationX: int,
camRotationY: int,
camPositionX: float,
camPositionY: float,
camPositionZ: float,
camScaleX: float,
camScaleY: float,
camScaleZ: float,
camAngleX: int,
camAngleY: int,
camPointAx: float,
camPointAy: float,
camPointAz: float,
camPointBx: float,
camPointBy: float,
camPointBz: float,
camVariable: float):
self.camType = camType
self.camPriority = camPriority
self.camAdjType = camAdjType
self.camColType = camColType
xRot = common.BAMSToRad(camRotationX)
yRot = common.BAMSToRad(camRotationY)
posMtx = mathutils.Matrix.Translation((camPositionX, -camPositionZ, camPositionY))
rotMtx = mathutils.Euler((xRot, 0, yRot), 'XZY').to_matrix().to_4x4()
scaleMtx = common.matrixFromScale((1, 1, 1))
camPointRotMtx = mathutils.Euler((0, 0, 0), 'XZY').to_matrix().to_4x4()
camPointA_posMtx = mathutils.Matrix.Translation((camPointAx, -camPointAz, camPointAy))
camPointB_posMtx = mathutils.Matrix.Translation((camPointBx, -camPointBz, camPointBy))
self.camMtx = posMtx @ rotMtx @ scaleMtx
self.camPointAMtx = camPointA_posMtx @ camPointRotMtx @ scaleMtx
self.camPointBMtx = camPointB_posMtx @ camPointRotMtx @ scaleMtx
def ReadCamFile(path: str, context, bigEndian: bool, useEntryNum: bool, isSA2: bool):
fileR = fileHelper.FileReader(path)
fileR.setBigEndian(bigEndian)
camCount = fileR.rUInt(0)
print("Cameras: ", camCount)
camList = list()
if (isSA2):
print("SA2 Camera Import not Implemented")
else:
for i in range(camCount):
tmpAddr = 0x40 + (i * 0x40)
camList.append(sa1CamEntry(
fileR.rSByte(tmpAddr),
fileR.rSByte(tmpAddr + 0x01),
fileR.rSByte(tmpAddr + 0x02),
fileR.rSByte(tmpAddr + 0x03),
fileR.rUShort(tmpAddr + 0x04),
fileR.rUShort(tmpAddr + 0x06),
fileR.rFloat(tmpAddr + 0x08),
fileR.rFloat(tmpAddr + 0x0C),
fileR.rFloat(tmpAddr + 0x10),
fileR.rFloat(tmpAddr + 0x14),
fileR.rFloat(tmpAddr + 0x18),
fileR.rFloat(tmpAddr + 0x1C),
fileR.rUShort(tmpAddr + 0x20),
fileR.rUShort(tmpAddr + 0x22),
fileR.rFloat(tmpAddr + 0x24),
fileR.rFloat(tmpAddr + 0x28),
fileR.rFloat(tmpAddr + 0x2C),
fileR.rFloat(tmpAddr + 0x30),
fileR.rFloat(tmpAddr + 0x34),
fileR.rFloat(tmpAddr + 0x38),
fileR.rFloat(tmpAddr + 0x3C)
))
cName = os.path.splitext(os.path.basename(path))[0]
col = bpy.data.collections.new("CamFile_" + cName)
context.scene.collection.children.link(col)
for i, o in enumerate(camList):
#print(str(o))
if (useEntryNum):
name = str(i) + "_Cam_" + str(o.camType)
else:
name = "Cam_" + str(o.camType) + "_" + str(i)
cam = bpy.data.objects.new(name, None)
camA = bpy.data.objects.new(name + "_A", None)
camA.parent = cam
camB = bpy.data.objects.new(name + "_B", None)
camB.parent = cam
cam.matrix_world = o.camMtx
camA.matrix_world = o.camPointAMtx
camB.matrix_world = o.camPointBMtx
cam.empty_display_type = 'CUBE'
camA.empty_display_type = 'SPHERE'
camB.empty_display_type = 'SPHERE'
col.objects.link(camA)
col.objects.link(camB)
col.objects.link(cam)