-
Notifications
You must be signed in to change notification settings - Fork 0
/
MDLFile.h
148 lines (132 loc) · 2.78 KB
/
MDLFile.h
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
/*
MDLFile.h - Allegiance mdl files API header
Copyright (C) Kirth Gersen, 2001-2002. All rights reserved.
v 0.94
*/
#pragma once
#define MDLCOOKIE 0xDEBADF00
typedef struct SMDLL2
{
CString name;
long value;
} MDLL2;
#define MDLHEADERSIZE (2*2+4*4)
typedef struct SMDLHeader
{
short s1;
short s2;
long nb_tags;
long l2;
long l3;
long l4;
CString TagsNames[250];
MDLL2 L2Vals[250];
CString l3names[250];
} MDLHeader;
typedef char* MDLString;
typedef struct SMLDLight //size = 12 float
{
float red;
float green;
float blue;
float speed; // or time factor
float posx;
float posy;
float posz;
float todo1; // 1.25 (0 = crash !)
float todo2; // 0
float todo3; // 0.1
float todo4; // 0
float todo5; // 0.05
} MDLLight;
typedef struct SMDLFrameData // size = name + 9 float
{
CString name;
float posx;
float posy;
float posz;
float nx;
float ny;
float nz;
float px;
float py;
float pz;
} MDLFrameData;
typedef struct SMDLVertice
{
float x;
float y;
float z;
float mx;
float my;
float nx;
float ny;
float nz;
} MDLVertice;
typedef struct SMDLMesh
{
long nvertex;
long nfaces;
MDLVertice *vertices;
WORD *faces;
} MDLMesh;
#define MDLImageInitSize 20
typedef struct SMDLImage
{
long w;
long h;
long bw;
long bh;
BYTE undecoded[MDLImageInitSize];// 00 F8 00 00 E0 07 00 00 1F 00 00 00 00 00 00 00 00 CC CC CC
BYTE *bitmap;
} MDLImage;
const BYTE MDLImageInit[MDLImageInitSize] = {0x00,0xF8,0x00,0x00,0xE0,0x07,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC};
enum MDLType {mdl_empty,mdl_mesh,mdl_group,mdl_lod,mdl_image};
typedef struct SMDLObject
{
MDLType type;
int nchildren;
struct SMDLObject **childrens;
MDLMesh *mesh;
float *lodval;
int textidx;
MDLImage *image;
} MDLObject;
typedef MDLObject *PtrMDLObject;
class CMDLFile
{
public:
CMDLFile(void);
~CMDLFile(void);
bool ReadFromFile(CString sFileName);
bool SaveToXFile(CString sFileName);
bool SaveToBMP(CString fname);
bool FromBMP(CString fname, CString bname);
int NumLights;
MDLLight *Lights;
int NumFrameDatas;
MDLFrameData *FrameDatas;
MDLObject *RootObject;
CString ReadError;
int NumTextures;
CString *Textures;
float *FrameVal;
MDLObject *NewMDLObject(void);
MDLLight NewMDLLight(int r,int g,int b,int s);
protected:
CString ParseString(CFile *pcf);
void DumpMesh(CStdioFile *,MDLMesh *);
CString CMDLFile::DumpObject(PtrMDLObject,int);
void ObjectToXFile(PtrMDLObject po,CStdioFile *cf, CString level);
void SaveString(CFile *pcf,CString s);
void SaveTag(CFile *pcf,long tag);
void SaveObject(MDLObject *po,CFile *pcf, int GroupPos, int MeshPos, int TextPos, int TextGeoPos);
private:
long stack[200];
int stackpos;
public:
// save to .mdl binary format
bool SaveToFile(CString sPath);
};
#define MAX(x,y) ((x)>(y)?(x):(y))
#define Upper4(x) (((x)/4)*4+4)