Model/Legacy

From owdev
Revision as of 22:25, 8 June 2016 by Id-daemon (talk | contribs)
Jump to: navigation, search

Very WIP documentation of Model format. Most of these things are purely guesswork.

Model V2

based on files:

8df9647916c9dae2cbb511bddced445e - viewmodel

00ea3ad3535754bf7160e7210f647357 - weapon model

eacde9e9abf0ebd73dbc09688967bdf5 - character model

system: assumed metric

struct header
{
	f32	desc_bbox[16];
	u32*	data_blob;
	u32*	unk_struct1;
	u64*	eof;
	u64*	bone_hierarchy_info;	// ref 'nr_bones_absolute'
	u64*	bone_matrices_1;	// [4x4] row or column major (?) translation is in the last row
	u64*	bone_matrices_2;	// [4x4] row or column major (?) translation is in the last row
	u64*	bone_matrices_3;	// [4x3] or [3x4] row or column (?)
	u64*	bone_matrices_4;	// [4x3] or [3x4] row or column (?)
	u64*	bone_u16;		// '0000' with 0x10 padding
	u64*	bone_ids;		// ? u32 with irregular numeric error
	u64*	bone_binaries;		// pointer array into following binary packet
	u64*	bone_additional1;	// ref 'nr_bones_minus1' points to 0x1E0 eoh
	u64*	bone_additional2;	// ref 'nr_bones3'
	u64*	bone_additional3;	// ref 'nr_bones_absolute'
	u32	magic;			// only seems valid for 'dynamic' models
	u16	nr_bones_absolute;	// relative count of bone_matrices_1
	u16	nr_bones1;		// assumed 'rigid' part of skeleton
	u16	nr_bones2;		// usually represents the number of physical bones
	u16	nr_bones3;
	u16	nr_bone_x1;		// counts for more bone strcuts or indices or something else
	u16	nr_bone_x2;		// usage scenarios range from physics root
	u16	nr_bone_x3;		// to attachements to fixed bone indices
	u16	nr_bone_x4;		// for specific reasons
	u16	nr_bones_minus1;
	u16	pad;
	u8	unk3[16];		// unk3
	u32	unk4;
	u32	nr_input_elements;
	u32	unk5;
	u32	unk_one;		// 1.0
	f32	unk6[4];
	f32	unk7[4];
	f32	unk8[4];
	u32	unk9[4];		// 3x 0 followed by 0xFFFF7F7F
	f32	unkA[4];
	u32	unkB[4];
	u32	unkC;
	u16	nr_materials_a;
	u16	nr_materials_b;		// commonly identical to _a
	u32	unkD;
	u32	unkE;
	u8	nr_vertex_buffer_desc;	// offset 0x150
	u8	nr_index_buffer_desc;
	u8	nr_some_flags;
	u8	nr_submesh_desc;
	u32	nr_something2;
	u64*	unk_struct2;		// array of amount unreferenced (it'd be bad) or should be unk3[11]
	u64*	material_lookup;	// u64 hash array of still unknown 'filesystem' specs
	u64*	submesh_desc;		// array
	u64*	vertex_buffer_desc;	// array
	u64*	index_buffer_desc;	// array
	u64*	desc4;		
	u64*	skeleton_id_desc;	// assumed. values 102 and 101 found in a mesh with lots of bones
	u64*	desc6;
	u64*	unk_struct3;
	u64*	desc8;
	u64*	phys_ref_desc;		// assumed. found in meshes with cloth physics.
	u64*	descA;
	u64*	physics_desc;		// extend unknown. default string contained is 'cloth physics'
	u64*	unk_struct1;
	u64*	descD;
	u64*	descE;
	u64*	descF;
};

struct submesh_desc			// 'drawcall' assembly info
{
	s64	bone_table_index;	// assumed. relative to bone infos in the header.
	u32	unk1;
	f32	unk2[10];
	u32	vertex_id_start;	// mul vertex buffer stream stride(s) to get releative offset(s).
	u16	index_id_start;
	u16	index_id_end;
	u16	nr_indices_to_draw;	// 'draw' means div 3 -> triangles to assemble.
	u16	nr_vertices_to_draw;	// 'draw' means run thru vertex shader. index relative.
	u8	bone_id_offset;
	u8	vertex_buffer_used;	// see descriptors
	u8	index_buffer_used;	// see descriptors
	u8	value1;			// flags, formats, enums, shader relevant (?)
	u8	material;		// see material_lookup
	u8	LOD_flags;		// bit 1 = highest LOD
	u8	value4;			// flags, formats, enums, shader relevant (?)
};

struct vertex_buffer_desc
{
	u32	nr_input_elements;
	u32	unk1;			// some binary
	u8	stride_stream1;
	u8	stride_stream2;
	u8	nr_vertex_elements_desc;
	u8	unk1;		
	u32	unk2;			// 0x00ed
	u64	effed[2];		// 0xFFed
	u64*	vertex_elements_desc;	// array
	u64*	data_stream1;		// see vertex_element_desc
	u64*	data_stream2;		// see vertex_element_desc
};

struct vertex_element_desc
{
	u8	semantic_type;		// it's called semantics.
	u8	semantic_index;		// example 1st, 2nd, 3rd pair of UVs
	u8	data_format;			
	u8	stream_number;
	u16	unk;			// always 0
	u16	stride_offset;
};

enum semantic_type			// semantics names can be found in DXBC files. not relevant here.
{
	POSITION	= 0,
	NORMAL		= 1,
	COLOR		= 2,		// actually unknown, just a loud guess
	TANGENT		= 3,
	BONE_INDICES	= 4,
	BONE_WEIGHT	= 5,
	UNKNOWN1	= 6,
	UNKNOWN2	= 7,
	UNKNOWN3	= 8,
	TEXCOORD	= 9,
	VERTEX_ID	= 10
};

enum data_format			// c/p DXGI_FORMAT_. RGBA == XYZW. usage relevant. incomplete.
{
	R32G32B32_FLOAT	= 2,
	R16G16_FLOAT	= 4,
	R8G8B8A8_UINT	= 6,
	R8G8B8A8_UNORM	= 8,
	R8G8B8A8_SNORM	= 9,
	R32_UINT	= 12
};

struct index_buffer_desc
{
	u32	nr_indices;		// or u64 without format (?) is uncommon
	u32	format;			// i16 or i32 is guessed 0 = i16
	u64	effed;			// 0xFFed
	u64*	data_streami;		
};

struct unk_struct1
{
	u32	unk[20];
};	

struct unk_struct2
{
	mat44	unk_purpose;
	u32	unk1[4];
	u64*	unk_binary;		// binary stream following
	u32	pad[2];
};

struct unk_struct3			// more or less based on weapon model. assumed collision data.
{
	u64*	data_vec3;		// point cloud looks like something
	u64*	data_vec4;		// or 2 vec2. amount calced.
	u64*	data_unk1;		// got a pattern but looks weird
	u64*	data_unk2;
	vec3	unk1;
	u32	nr_data_vec3;
	u32	nr_data_vec4;
	f32	unkn2[2];
	u32	effed1[2];
	f32	unk3[12];
	u16	effed2;
	u8	unk4[18];
};

struct bone_hierarchy_info
{
	s16	children;               // no. of children + some bit flags.
	s16*	offset;                 // hierarchy offset, probably parent 
	s16	parentIndex;		// if 0xFFFF / -1 there's no parent
}