Niotso
git revision 558726a9f13d7c3423a683dd2f4323589b66c310
The New Implementation of The Sims Online
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
Libraries
libvitaboy
libvitaboy.hpp
Go to the documentation of this file.
1
/*
2
libvitaboy - Open source OpenGL TSO character animation library
3
libvitaboy.hpp - Copyright (c) 2012 Niotso Project <http://niotso.org/>
4
Author(s): Fatbag <X-Fi6@phppoll.org>
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#ifndef LIBVITABOY_HPP
20
#define LIBVITABOY_HPP
21
22
#include <stdlib.h>
23
#include <stdint.h>
24
#include <string.h>
25
#include <stdio.h>
26
#include <
FileHandler.hpp
>
27
28
/****
29
** Bytestream
30
*/
31
32
class
VBFile_t
{
33
private
:
34
const
uint8_t *
Buffer
, *
Position
;
35
unsigned
Size
;
36
37
public
:
38
inline
void
set
(
const
void
*_Buffer,
unsigned
_Size){
39
Buffer
= (
const
uint8_t*) _Buffer;
40
Position
= (
const
uint8_t*) _Buffer;
41
Size
= _Size;
42
}
43
44
inline
unsigned
getpos
(){
45
return
Position
-
Buffer
;
46
}
47
48
inline
void
seekto
(
unsigned
offset){
49
Position
=
Buffer
+offset;
50
}
51
inline
void
seekahead
(
unsigned
count){
52
Position
+= count;
53
}
54
inline
void
seekback
(
unsigned
count){
55
Position
-= count;
56
}
57
58
inline
uint32_t
readint32
(){
59
uint32_t value = (uint32_t)((
Position
[0]<<(8*3)) | (
Position
[1]<<(8*2)) | (
Position
[2]<<(8*1)) | (
Position
[3]<<(8*0)));
60
Position
+= 4;
61
return
value;
62
}
63
64
inline
uint32_t
readint16
(){
65
uint16_t value = (uint16_t)((
Position
[0]<<(8*1)) | (
Position
[1]<<(8*0)));
66
Position
+= 2;
67
return
value;
68
}
69
70
inline
uint32_t
readint8
(){
71
uint8_t value = (uint8_t)((
Position
[0]<<(8*0)));
72
Position
+= 1;
73
return
value;
74
}
75
76
inline
float
readfloat
(){
77
union
{ uint32_t i;
float
f; } value;
78
value.i = (uint32_t)((
Position
[0]<<(8*0)) | (
Position
[1]<<(8*1)) | (
Position
[2]<<(8*2)) | (
Position
[3]<<(8*3)));
79
Position
+= 4;
80
return
value.f;
81
}
82
83
inline
void
readbytes
(
void
* Destination,
unsigned
length){
84
memcpy(Destination,
Position
, length);
85
Position
+= length;
86
}
87
88
inline
char
*
readstring
(){
89
//Read a Pascal string with 1 length byte
90
unsigned
length =
readint8
();
91
char
*
string
= (
char
*) malloc(length+1);
92
readbytes
(
string
, length);
93
string
[length] =
'\0'
;
94
return
string;
95
}
96
97
inline
char
*
readstring2
(){
98
//Read a Pascal string with 2 length bytes
99
unsigned
length =
readint16
();
100
char
*
string
= (
char
*) malloc(length+1);
101
readbytes
(
string
, length);
102
string
[length] =
'\0'
;
103
return
string;
104
}
105
};
106
107
extern
VBFile_t
VBFile
;
108
109
/****
110
** Common
111
*/
112
113
enum
ReadGroup
{
114
NOGROUP
,
115
READGROUP
116
};
117
118
struct
Translation_t
{
119
float
x
,
y
,
z
;
120
};
121
122
struct
Rotation_t
{
123
float
x
,
y
,
z
,
w
;
124
};
125
126
struct
KeyValuePair_t
{
127
char
*
Key
;
128
char
*
Value
;
129
};
130
131
struct
Prop_t
{
132
uint32_t
EntriesCount
;
133
KeyValuePair_t
*
Entries
;
134
};
135
136
struct
PropsList_t
{
137
uint32_t
PropsCount
;
138
Prop_t
*
Props
;
139
};
140
141
void
ReadAsset
(
Asset_t
& Asset,
bool
ReadGroup
);
142
void
ReadPropEntry
(
KeyValuePair_t
& Entry);
143
void
ReadPropEntries
(
Prop_t
& Prop);
144
void
ReadPropsList
(
PropsList_t
& PropsList);
145
float
DotProduct
(
Rotation_t
* q1,
Rotation_t
* q2);
146
void
Normalize
(
Rotation_t
* q);
147
void
CombineQuaternions
(
Rotation_t
* Destination,
Rotation_t
* Source);
148
void
FindQuaternionMatrix
(
float
* Matrix,
Rotation_t
* Quaternion);
149
150
151
/****
152
** Animation (*.anim)
153
*/
154
155
struct
TimeProp_t
{
156
uint32_t
ID
;
157
PropsList_t
PropsList
;
158
};
159
160
struct
TimePropsList_t
{
161
uint32_t
TimePropsCount
;
162
TimeProp_t
*
TimeProps
;
163
};
164
165
struct
Motion_t
{
166
uint32_t
Unknown
;
167
char
*
BoneName
;
168
uint32_t
FrameCount
;
169
float
Duration
;
//Converted to seconds
170
uint8_t
HasTranslation
;
171
uint8_t
HasRotation
;
172
uint32_t
FirstTranslation
;
173
uint32_t
FirstRotation
;
174
Translation_t
*
Translations
;
175
Rotation_t
*
Rotations
;
176
177
uint8_t
HasPropsLists
;
178
uint32_t
PropsListsCount
;
179
PropsList_t
*
PropsLists
;
180
181
uint8_t
HasTimePropsLists
;
182
uint32_t
TimePropsListsCount
;
183
TimePropsList_t
*
TimePropsLists
;
184
};
185
186
struct
Animation_t
{
187
uint32_t
Version
;
188
char
*
Name
;
189
float
Duration
;
//Converted to seconds
190
float
Distance
;
191
uint8_t
IsMoving
;
192
uint32_t
TranslationsCount
;
193
uint32_t
RotationsCount
;
194
uint32_t
MotionsCount
;
195
196
unsigned
TranslationsOffset
;
197
unsigned
RotationsOffset
;
198
199
Motion_t
*
Motions
;
200
};
201
202
void
ReadAnimation
(
Animation_t
&
Animation
);
203
void
ReadMotion
(
Animation_t
&
Animation
,
Motion_t
& Motion);
204
void
ReadPropsLists
(
Motion_t
& Motion);
205
void
ReadTimePropsList
(
TimePropsList_t
& TimePropsList);
206
void
ReadTimePropsLists
(
Motion_t
& Motion);
207
208
209
/****
210
** Appearance (*.apr)
211
*/
212
213
struct
Appearance_t
{
214
uint32_t
Version
;
215
Asset_t
Thumbnail
;
216
uint32_t
BindingCount
;
217
Asset_t
*
Bindings
;
218
};
219
220
void
ReadAppearance
(
Appearance_t
& Appearance);
221
222
223
/****
224
** Binding (*.bnd)
225
*/
226
227
struct
Binding_t
{
228
uint32_t
Version
;
229
char
*
BoneName
;
230
uint32_t
MeshDef
;
231
Asset_t
Mesh
;
232
uint32_t
AppearanceDef
;
233
Asset_t
Appearance
;
234
};
235
236
void
ReadBinding
(
Binding_t
& Binding);
237
238
239
/****
240
** Collection (*.col)
241
*/
242
243
struct
PODef_t
{
244
uint32_t
Index
;
245
Asset_t
PO
;
246
};
247
248
struct
Collection_t
{
249
uint32_t
POCount
;
250
PODef_t
*
PurchasableOutfits
;
251
};
252
253
void
ReadCollection
(
Collection_t
& Collection);
254
255
256
/****
257
** Hand Group (*.hag)
258
*/
259
260
struct
HandGroup_t
{
261
uint32_t
Version
;
262
Asset_t
HandAppearances
[18];
263
};
264
265
void
ReadHandGroup
(
HandGroup_t
& HandGroup);
266
267
268
/****
269
** Mesh (*.mesh)
270
*/
271
272
struct
TextureVertex_t
{
273
float
u
,
v
;
274
};
275
276
struct
Coord_t
{
277
float
x
,
y
,
z
;
278
};
279
280
struct
TextureCoord_t
{
281
float
u
,
v
;
282
};
283
284
struct
NormalCoord_t
{
285
float
x
,
y
,
z
;
286
};
287
288
struct
BlendData_t
{
289
float
Weight
;
290
unsigned
OtherVertex
;
291
};
292
293
struct
Vertex_t
{
294
Coord_t
Coord
;
295
TextureCoord_t
TextureCoord
;
296
NormalCoord_t
NormalCoord
;
297
298
unsigned
BoneIndex
;
299
BlendData_t
BlendData
;
300
};
301
302
struct
Face_t
{
303
unsigned
VertexA
,
VertexB
,
VertexC
;
304
};
305
306
struct
BoneBinding_t
{
307
unsigned
BoneIndex
;
308
unsigned
FirstRealVertex
;
309
unsigned
RealVertexCount
;
310
unsigned
FirstBlendVertex
;
311
unsigned
BlendVertexCount
;
312
};
313
314
struct
Mesh_t
{
315
uint32_t
Version
;
316
uint32_t
BoneCount
;
317
char
**
BoneNames
;
318
uint32_t
FaceCount
;
319
Face_t
*
FaceData
;
320
uint32_t
BindingCount
;
321
BoneBinding_t
*
BoneBindings
;
322
uint32_t
RealVertexCount
;
323
uint32_t
BlendVertexCount
;
324
uint32_t
TotalVertexCount
;
325
Vertex_t
*
VertexData
;
326
Vertex_t
*
TransformedVertexData
;
327
};
328
329
void
ReadMesh
(
Mesh_t
& Mesh);
330
331
332
/****
333
** Outfit (*.oft)
334
*/
335
336
enum
OutfitColor
{
337
OutfitColor_Light
,
338
OutfitColor_Medium
,
339
OutfitColor_Dark
340
};
341
342
enum
OutfitRegion
{
343
OutfitRegion_Head
= 0,
344
OutfitRegion_Body
= 18
345
};
346
347
struct
Outfit_t
{
348
uint32_t
Version
;
349
uint32_t
Unknown
;
350
Asset_t
Appearance
[3];
351
uint32_t
Group
;
352
uint32_t
Region
;
353
};
354
355
void
ReadOutfit
(
Outfit_t
& Outfit);
356
357
358
/****
359
** Purchasable Outfit (*.po)
360
*/
361
362
struct
PurchasableOutfit_t
{
363
uint32_t
Version
;
364
uint32_t
Unknown
;
365
uint32_t
OutfitDef
;
366
Asset_t
Outfit
;
367
uint32_t
CollectionDef
;
368
Asset_t
Collection
;
369
};
370
371
void
ReadPurchasableOutfit
(
PurchasableOutfit_t
& PurchasableOutfit);
372
373
374
/****
375
** Skeleton (*.skel)
376
*/
377
378
struct
Bone_t
{
379
uint32_t
Unknown
;
380
char
*
Name
;
381
char
*
ParentsName
;
382
uint8_t
HasProps
;
383
PropsList_t
PropsList
;
384
Translation_t
Translation
;
385
Rotation_t
Rotation
;
386
uint32_t
CanTranslate
;
387
uint32_t
CanRotate
;
388
uint32_t
CanBlend
;
389
float
WiggleValue
;
390
float
WigglePower
;
391
392
unsigned
ChildrenCount
;
393
Bone_t
**
Children
;
394
};
395
396
struct
Skeleton_t
{
397
uint32_t
Version
;
398
char
*
Name
;
399
uint16_t
BoneCount
;
400
Bone_t
*
Bones
;
401
};
402
403
void
ReadSkeleton
(
Skeleton_t
& Bone);
404
void
ReadBone
(
Skeleton_t
&
Skeleton
,
Bone_t
& Bone,
unsigned
Index);
405
unsigned
FindBone
(
Skeleton_t
&
Skeleton
,
const
char
* BoneName,
unsigned
Count);
406
407
#endif
Generated on Sat Jun 15 2013 03:02:15 for Niotso by
1.8.4