1 //
2 // OGF v3 - builds 1098, 1114, 1154
3 // OGF v4 - builds 2215, 2945, 2939, 2947+
4 // OGF v4+ - builds 3120, 3456+
5 //
6 // FIXME: merge with xr_ogf.h?
7 //
8 #ifndef __GNUC__
9 #pragma once
10 #endif
11 #ifndef __XR_OGF_FORMAT_H__
12 #define __XR_OGF_FORMAT_H__
13 
14 #include "xr_vector3.h"
15 #include "xr_quaternion.h"
16 #include "xr_aabb.h"
17 #include "xr_sphere.h"
18 #include "xr_cylinder.h"
19 #include "xr_color.h"
20 #include "xr_skeleton.h"
21 
22 namespace xray_re {
23 
24 // OGF chunk ids.
25 enum ogf_chunk_id {
26 	OGF_HEADER		= 0x1,
27 
28 	//build 729
29 	OGF2_TEXTURE        = 0x2,
30 	OGF2_TEXTURE_L      = 0x3,
31 	OGF2_BBOX           = 0x6,
32 	OGF2_VERTICES       = 0x7,
33 	OGF2_INDICES        = 0x8,
34 	OGF2_VCONTAINER     = 0xb,
35 	OGF2_BSPHERE        = 0xc,
36 
37 	OGF3_TEXTURE		= 0x2,
38 	OGF3_TEXTURE_L		= 0x3,
39 	OGF3_CHILD_REFS		= 0x5,
40 	OGF3_BBOX			= 0x6,
41 	OGF3_VERTICES		= 0x7,
42 	OGF3_INDICES		= 0x8,
43 	OGF3_LODDATA		= 0x9,	// not sure
44 	OGF3_VCONTAINER		= 0xa,
45 	OGF3_BSPHERE		= 0xb,
46 	OGF3_CHILDREN_L		= 0xc,
47 	OGF3_S_BONE_NAMES	= 0xd,
48 	OGF3_S_MOTIONS		= 0xe,// build 1469 - 1580
49 	OGF3_DPATCH			= 0xf,	// guessed name
50 	OGF3_LODS			= 0x10,	// guessed name
51 	OGF3_CHILDREN		= 0x11,
52 	OGF3_S_SMPARAMS		= 0x12,// build 1469
53 	OGF3_ICONTAINER		= 0x13,// build 1865
54 	OGF3_S_SMPARAMS_NEW = 0x14,// build 1472 - 1865
55 	OGF3_LODDEF2		= 0x15,// build 1865
56 	OGF3_TREEDEF2		= 0x16,// build 1865
57 	OGF3_S_IKDATA_0     = 0x17,// build 1475 - 1580
58 	OGF3_S_USERDATA     = 0x18,// build 1537 - 1865
59 	OGF3_S_IKDATA       = 0x19,// build 1616 - 1829, 1844
60 	OGF3_S_MOTIONS_NEW  = 0x1a,// build 1616 - 1865
61 	OGF3_S_DESC         = 0x1b,// build 1844
62 	OGF3_S_IKDATA_2     = 0x1C,// build 1842 - 1865
63 	OGF3_S_MOTION_REFS  = 0x1D,// build 1842
64 
65 	OGF4_TEXTURE		= 0x2,
66 	OGF4_VERTICES		= 0x3,
67 	OGF4_INDICES		= 0x4,
68 	OGF4_P_MAP			= 0x5,
69 	OGF4_SWIDATA		= 0x6,
70 	OGF4_VCONTAINER		= 0x7,
71 	OGF4_ICONTAINER		= 0x8,
72 	OGF4_CHILDREN		= 0x9,
73 	OGF4_CHILDREN_L		= 0xa,
74 	OGF4_LODDEF2		= 0xb,
75 	OGF4_TREEDEF2		= 0xc,
76 	OGF4_S_BONE_NAMES	= 0xd,
77 	OGF4_S_MOTIONS		= 0xe,
78 	OGF4_S_SMPARAMS		= 0xf,
79 	OGF4_S_IKDATA		= 0x10,
80 	OGF4_S_USERDATA		    = 0x11,
81 	OGF4_S_DESC             = 0x12,
82 	OGF4_S_MOTION_REFS_0    = 0x13,	// pre-CS format
83 	OGF4_SWICONTAINER       = 0x14,
84 	OGF4_GCONTAINER		= 0x15,
85 	OGF4_FASTPATH		= 0x16,
86 	OGF4_S_LODS		= 0x17,
87 	OGF4_S_MOTION_REFS_1	= 0x18,	// introduced in clear sky
88 };
89 
90 // Common OGF data structures.
91 typedef fbox ogf_bbox;
92 typedef fsphere ogf_bsphere;
93 
94 // OGF header definitions.
95 enum ogf_version {
96 	OGF2_VERSION    = 2,
97 	OGF3_VERSION    = 3,
98 	OGF4_VERSION    = 4,
99 };
100 
101 enum ogf_model_type {
102 	MT3_NORMAL		= 0,	// Fvisual
103 	MT3_HIERRARHY		= 0x1,	// FHierrarhyVisual
104 	MT3_PROGRESSIVE		= 0x2,	// FProgressiveFixedVisual
105 	MT3_SKELETON_GEOMDEF_PM	= 0x3,	// CSkeletonX_PM
106 	MT3_SKELETON_ANIM	= 0x4,	// CKinematics
107 	MT3_DETAIL_PATCH	= 0x6,	// FDetailPatch
108 	MT3_SKELETON_GEOMDEF_ST	= 0x7,	// CSkeletonX_ST
109 	MT3_CACHED		= 0x8,	// FCached
110 	MT3_PARTICLE		= 0x9,	// CPSVisual
111 	MT3_PROGRESSIVE2	= 0xa,	// FProgressive
112 	MT3_LOD			= 0xb,	// FLOD build 1472 - 1865
113 	MT3_TREE		= 0xc,	// FTreeVisual build 1472 - 1865
114 	//				= 0xd,	// CParticleEffect 1844
115 	//				= 0xe,	// CParticleGroup 1844
116 	MT3_SKELETON_RIGID	= 0xf,	// CSkeletonRigid 1844
117 
118 	MT4_NORMAL		= 0,	// Fvisual
119 	MT4_HIERRARHY		= 0x1,	// FHierrarhyVisual
120 	MT4_PROGRESSIVE		= 0x2,	// FProgressive
121 	MT4_SKELETON_ANIM	= 0x3,	// CKinematicsAnimated
122 	MT4_SKELETON_GEOMDEF_PM	= 0x4,	// CSkeletonX_PM
123 	MT4_SKELETON_GEOMDEF_ST	= 0x5,	// CSkeletonX_ST
124 	MT4_LOD			= 0x6,	// FLOD
125 	MT4_TREE_ST		= 0x7,	// FTreeVisual_ST
126 	MT4_PARTICLE_EFFECT	= 0x8,	// PS::CParticleEffect
127 	MT4_PARTICLE_GROUP	= 0x9,	// PS::CParticleGroup
128 	MT4_SKELETON_RIGID	= 0xa,	// CKinematics
129 	MT4_TREE_PM		= 0xb,	// FTreeVisual_PM
130 
131 	MT4_OMF			= 0x40,	// fake model type to distinguish .omf
132 };
133 
134 struct ogf3_header {
135 	uint8_t		version;
136 	uint8_t		type;
137 	uint16_t	unused;		// really?
138 };
139 
140 struct ogf4_header {
141 	uint8_t		format_version;
142 	uint8_t		type;
143 	uint16_t	shader_id;
144 	ogf_bbox	bb;
145 	ogf_bsphere	bs;
146 };
147 
148 // Vertex formats.
149 enum ogf_vertex_format {
150 	OGF_VERTEXFORMAT_FVF		= 0x112,
151 
152 	OGF3_VERTEXFORMAT_FVF_1L	= 0x12071980,
153 	OGF3_VERTEXFORMAT_FVF_2L	= 0x240e3300,
154 
155 	OGF4_VERTEXFORMAT_FVF_1L	= 0x12071980,
156 	OGF4_VERTEXFORMAT_FVF_2L	= 0x240e3300,
157 	OGF4_VERTEXFORMAT_FVF_NL	= 0x36154c80,
158 
159 	OGF4_VERTEXFORMAT_FVF_1L_CS	= 0x1,
160 	OGF4_VERTEXFORMAT_FVF_2L_CS	= 0x2,
161 	OGF4_VERTEXFORMAT_FVF_3L_CS	= 0x3,
162 	OGF4_VERTEXFORMAT_FVF_4L_CS	= 0x4,
163 };
164 
165 struct ogf_vert_render {
166 	fvector3	p;
167 	fvector3	n;
168 	float		u, v;
169 };
170 
171 struct ogf3_vert_boned_1w {
172 	fvector3	p;
173 	fvector3	n;
174 	float		u, v;
175 	uint32_t	matrix;
176 };
177 
178 struct ogf4_vert_boned_1w {
179 	fvector3	p;
180 	fvector3	n, t, b;
181 	float		u, v;
182 	uint32_t	matrix;
183 };
184 
185 struct ogf4_vert_boned_2w {
186 	uint16_t	matrix0, matrix1;
187 	fvector3	p;
188 	fvector3	n, t, b;
189 	float		w;
190 	float		u, v;
191 };
192 
193 // FIXME: check the actual engine code.
194 struct ogf4_vert_boned_3w {
195 	uint16_t	matrices[3];
196 	uint16_t	unused;
197 	fvector3	p;
198 	fvector3	n, t, b;
199 	float		w[2];
200 	float		u, v;
201 };
202 
203 struct ogf4_vert_boned_4w {
204 	uint16_t	matrices[4];
205 	fvector3	p;
206 	fvector3	n, t, b;
207 	float		w[3];
208 	float		u, v;
209 };
210 
211 enum {
212 	OGF3_HOPPE_HEADER	= 1,
213 	OGF3_HOPPE_VERT_SPLITS	= 2,
214 	OGF3_HOPPE_FIX_FACES	= 3,
215 };
216 
217 // OGF v3 LOD information in fixed progressive (Hoppe's PM).
218 struct ogf3_vsplit {
219 	uint16_t	vert;
220 	uint8_t		new_tris;
221 	uint8_t		fix_faces;
222 };
223 
224 // OGF v4 progressive mesh definitions (SWPM).
225 struct ogf4_slide_window {
226 	uint32_t	offset;
227 	uint16_t	num_tris;
228 	uint16_t	num_verts;
229 };
230 
231 // Bone and kinematics definitions are mostly shared with editor object.
232 const uint32_t OGF3_S_JOINT_IK_DATA_VERSION = 1;
233 const uint32_t OGF4_S_JOINT_IK_DATA_VERSION = 1;
234 
235 // Motions definitions.
236 const uint16_t OGF3_S_SMPARAMS_VERSION_1 = 1;	// 1829
237 const uint16_t OGF3_S_SMPARAMS_VERSION_3 = 3;	// 1842
238 const uint16_t OGF4_S_SMPARAMS_VERSION_3 = 3;	// 2215, 2947+
239 const uint16_t OGF4_S_SMPARAMS_VERSION_4 = 4;	// 3120, 3456+
240 
241 const float OGF3_MOTION_FPS = 30.f;
242 const float OGF4_MOTION_FPS = 30.f;
243 
244 enum ogf3_motion_type {
245 	SMT_FX		= 0,
246 	SMT_CYCLE	= 1,
247 };
248 
249 enum ogf4_key_presence_flag {
250 	KPF_T_PRESENT	= 0x01,
251 	KPF_R_ABSENT	= 0x02,
252 	KPF_T_HQ	= 0x04,		// 3456+
253 };
254 
255 struct ogf_key_qr {
256 	int16_t				x, y, z, w;
257 	template<typename T> void	dequantize(_quaternion<T>& q) const;
258 };
259 
dequantize(_quaternion<T> & q)260 template<typename T> inline void ogf_key_qr::dequantize(_quaternion<T>& q) const
261 {
262 	const T m = 1/T(32767);
263 	q.x = x*m;
264 	q.y = y*m;
265 	q.z = z*m;
266 	q.w = w*m;
267 }
268 
269 template<typename T> struct _ogf4_key_qt {
270 	T	x, y, z;
271 	void	dequantize(fvector3& value, const fvector3& scale) const;
272 };
273 
274 typedef _ogf4_key_qt<int8_t> ogf4_key_qt;
275 typedef _ogf4_key_qt<int16_t> ogf4_key_qt_hq;
276 
dequantize(fvector3 & value,const fvector3 & scale)277 template<typename T> inline void _ogf4_key_qt<T>::dequantize(fvector3& value, const fvector3& scale) const
278 {
279 	value.x = x*scale.x;
280 	value.y = y*scale.y;
281 	value.z = z*scale.z;
282 };
283 
284 struct ogf_motion_def {
285 	uint16_t	bone_or_part;
286 	uint16_t	motion;
287 	float		speed;
288 	float		power;
289 	float		accrue;
290 	float		falloff;
291 };
292 
293 // level tree definitions
294 struct ogf4_5color {
295 	fvector3	rgb;
296 	float		hemi;
297 	float		sun;
298 };
299 
300 // level mesh LOD definitions (billboards)
301 struct ogf4_lod_vertex {
302 	fvector3	v;
303 	fvector2	t;
304 	rgba32		c_rgb_hemi;
305 	uint8_t		c_sun;
306 	uint8_t		pad[3];
307 };
308 
309 // on-disk format!!!
310 struct ogf4_lod_face {
311 	ogf4_lod_vertex	v[4];
312 };
313 
314 } // end of namespace xray_re
315 
316 #endif
317