Commit 6348888a authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

d3dx9: Unify calling parse_mesh helper functions.

parent 6787e3c3
...@@ -37,6 +37,11 @@ ...@@ -37,6 +37,11 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx); WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
/* for provide_flags parameters */
#define PROVIDE_MATERIALS 0x1
#define PROVIDE_SKININFO 0x2
#define PROVIDE_ADJACENCY 0x4
struct d3dx9_mesh struct d3dx9_mesh
{ {
ID3DXMesh ID3DXMesh_iface; ID3DXMesh ID3DXMesh_iface;
...@@ -2611,6 +2616,7 @@ struct mesh_data { ...@@ -2611,6 +2616,7 @@ struct mesh_data {
struct ID3DXSkinInfo *skin_info; struct ID3DXSkinInfo *skin_info;
unsigned int bone_count; unsigned int bone_count;
unsigned int skin_weights_info_count;
}; };
static HRESULT parse_texture_filename(ID3DXFileData *filedata, char **filename_out) static HRESULT parse_texture_filename(ID3DXFileData *filedata, char **filename_out)
...@@ -2752,7 +2758,7 @@ static void destroy_materials(struct mesh_data *mesh) ...@@ -2752,7 +2758,7 @@ static void destroy_materials(struct mesh_data *mesh)
mesh->material_indices = NULL; mesh->material_indices = NULL;
} }
static HRESULT parse_material_list(ID3DXFileData *filedata, struct mesh_data *mesh) static HRESULT parse_material_list(ID3DXFileData *filedata, struct mesh_data *mesh, DWORD flags)
{ {
ID3DXFileData *child = NULL; ID3DXFileData *child = NULL;
unsigned int material_count; unsigned int material_count;
...@@ -2764,6 +2770,9 @@ static HRESULT parse_material_list(ID3DXFileData *filedata, struct mesh_data *me ...@@ -2764,6 +2770,9 @@ static HRESULT parse_material_list(ID3DXFileData *filedata, struct mesh_data *me
HRESULT hr; HRESULT hr;
GUID type; GUID type;
if (!(flags & PROVIDE_MATERIALS))
return S_OK;
destroy_materials(mesh); destroy_materials(mesh);
hr = filedata->lpVtbl->Lock(filedata, &data_size, &data); hr = filedata->lpVtbl->Lock(filedata, &data_size, &data);
...@@ -2867,7 +2876,7 @@ end: ...@@ -2867,7 +2876,7 @@ end:
return hr; return hr;
} }
static HRESULT parse_texture_coords(ID3DXFileData *filedata, struct mesh_data *mesh) static HRESULT parse_texture_coords(ID3DXFileData *filedata, struct mesh_data *mesh, DWORD flags)
{ {
const uint32_t *data; const uint32_t *data;
SIZE_T data_size; SIZE_T data_size;
...@@ -2925,7 +2934,7 @@ end: ...@@ -2925,7 +2934,7 @@ end:
return hr; return hr;
} }
static HRESULT parse_vertex_colors(ID3DXFileData *filedata, struct mesh_data *mesh) static HRESULT parse_vertex_colors(ID3DXFileData *filedata, struct mesh_data *mesh, DWORD flags)
{ {
unsigned int color_count, i; unsigned int color_count, i;
const uint32_t *data; const uint32_t *data;
...@@ -3004,7 +3013,7 @@ end: ...@@ -3004,7 +3013,7 @@ end:
return hr; return hr;
} }
static HRESULT parse_normals(ID3DXFileData *filedata, struct mesh_data *mesh) static HRESULT parse_normals(ID3DXFileData *filedata, struct mesh_data *mesh, DWORD flags)
{ {
unsigned int num_face_indices = mesh->num_poly_faces * 2 + mesh->num_tri_faces; unsigned int num_face_indices = mesh->num_poly_faces * 2 + mesh->num_tri_faces;
DWORD *index_out_ptr; DWORD *index_out_ptr;
...@@ -3110,7 +3119,7 @@ end: ...@@ -3110,7 +3119,7 @@ end:
return hr; return hr;
} }
static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data *mesh_data) static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data *mesh_data, DWORD flags)
{ {
const BYTE *data; const BYTE *data;
SIZE_T data_size; SIZE_T data_size;
...@@ -3118,6 +3127,15 @@ static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data ...@@ -3118,6 +3127,15 @@ static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data
TRACE("filedata %p, mesh_data %p.\n", filedata, mesh_data); TRACE("filedata %p, mesh_data %p.\n", filedata, mesh_data);
if (!(flags & PROVIDE_SKININFO))
return S_OK;
if (mesh_data->skin_info)
{
WARN("Skin mesh header already encountered\n");
return E_FAIL;
}
if (FAILED(hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data))) if (FAILED(hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data)))
return hr; return hr;
...@@ -3136,8 +3154,9 @@ static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data ...@@ -3136,8 +3154,9 @@ static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data
return hr; return hr;
} }
static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data *mesh_data, unsigned int index) static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data *mesh_data, DWORD flags)
{ {
unsigned int index = mesh_data->skin_weights_info_count;
unsigned int influence_count; unsigned int influence_count;
const char *name; const char *name;
const BYTE *data; const BYTE *data;
...@@ -3146,6 +3165,15 @@ static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data ...@@ -3146,6 +3165,15 @@ static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data
TRACE("filedata %p, mesh_data %p, index %u.\n", filedata, mesh_data, index); TRACE("filedata %p, mesh_data %p, index %u.\n", filedata, mesh_data, index);
if (!(flags & PROVIDE_SKININFO))
return S_OK;
if (!mesh_data->skin_info)
{
WARN("Skin weights found but skin mesh header not encountered yet.\n");
return E_FAIL;
}
if (FAILED(hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data))) if (FAILED(hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data)))
return hr; return hr;
...@@ -3173,17 +3201,13 @@ static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data ...@@ -3173,17 +3201,13 @@ static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data
hr = mesh_data->skin_info->lpVtbl->SetBoneOffsetMatrix(mesh_data->skin_info, index, hr = mesh_data->skin_info->lpVtbl->SetBoneOffsetMatrix(mesh_data->skin_info, index,
(const D3DMATRIX *)(data + influence_count * (sizeof(uint32_t) + sizeof(float)))); (const D3DMATRIX *)(data + influence_count * (sizeof(uint32_t) + sizeof(float))));
if (SUCCEEDED(hr))
++mesh_data->skin_weights_info_count;
return hr; return hr;
} }
/* for provide_flags parameters */
#define PROVIDE_MATERIALS 0x1
#define PROVIDE_SKININFO 0x2
#define PROVIDE_ADJACENCY 0x4
static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, DWORD provide_flags) static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, DWORD provide_flags)
{ {
unsigned int skin_weights_info_count = 0;
ID3DXFileData *child = NULL; ID3DXFileData *child = NULL;
const BYTE *data, *in_ptr; const BYTE *data, *in_ptr;
DWORD *index_out_ptr; DWORD *index_out_ptr;
...@@ -3203,6 +3227,8 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, ...@@ -3203,6 +3227,8 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data,
* } * }
*/ */
mesh_data->skin_weights_info_count = 0;
hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data); hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
...@@ -3308,37 +3334,19 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, ...@@ -3308,37 +3334,19 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data,
goto end; goto end;
if (IsEqualGUID(&type, &TID_D3DRMMeshNormals)) { if (IsEqualGUID(&type, &TID_D3DRMMeshNormals)) {
hr = parse_normals(child, mesh_data); hr = parse_normals(child, mesh_data, provide_flags);
} else if (IsEqualGUID(&type, &TID_D3DRMMeshVertexColors)) { } else if (IsEqualGUID(&type, &TID_D3DRMMeshVertexColors)) {
hr = parse_vertex_colors(child, mesh_data); hr = parse_vertex_colors(child, mesh_data, provide_flags);
} else if (IsEqualGUID(&type, &TID_D3DRMMeshTextureCoords)) { } else if (IsEqualGUID(&type, &TID_D3DRMMeshTextureCoords)) {
hr = parse_texture_coords(child, mesh_data); hr = parse_texture_coords(child, mesh_data, provide_flags);
} else if (IsEqualGUID(&type, &TID_D3DRMMeshMaterialList) && } else if (IsEqualGUID(&type, &TID_D3DRMMeshMaterialList)) {
(provide_flags & PROVIDE_MATERIALS)) hr = parse_material_list(child, mesh_data, provide_flags);
{ } else if (IsEqualGUID(&type, &DXFILEOBJ_XSkinMeshHeader)) {
hr = parse_material_list(child, mesh_data); hr = parse_skin_mesh_header(child, mesh_data, provide_flags);
} else if (provide_flags & PROVIDE_SKININFO) { } else if (IsEqualGUID(&type, &DXFILEOBJ_SkinWeights)) {
if (IsEqualGUID(&type, &DXFILEOBJ_XSkinMeshHeader)) { hr = parse_skin_weights_info(child, mesh_data, provide_flags);
if (mesh_data->skin_info) {
WARN("Skin mesh header already encountered\n");
hr = E_FAIL;
goto end;
}
hr = parse_skin_mesh_header(child, mesh_data);
if (FAILED(hr))
goto end;
} else if (IsEqualGUID(&type, &DXFILEOBJ_SkinWeights)) {
if (!mesh_data->skin_info) {
WARN("Skin weights found but skin mesh header not encountered yet\n");
hr = E_FAIL;
goto end;
}
hr = parse_skin_weights_info(child, mesh_data, skin_weights_info_count);
if (FAILED(hr))
goto end;
skin_weights_info_count++;
}
} }
if (FAILED(hr)) if (FAILED(hr))
goto end; goto end;
...@@ -3346,10 +3354,10 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, ...@@ -3346,10 +3354,10 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data,
child = NULL; child = NULL;
} }
if (mesh_data->skin_info && (skin_weights_info_count != mesh_data->bone_count)) if (mesh_data->skin_info && (mesh_data->skin_weights_info_count != mesh_data->bone_count))
{ {
WARN("Mismatch between skin weights info count %u and bones count %u from skin mesh header.\n", WARN("Mismatch between skin weights info count %u and bones count %u from skin mesh header.\n",
skin_weights_info_count, mesh_data->bone_count); mesh_data->skin_weights_info_count, mesh_data->bone_count);
hr = E_FAIL; hr = E_FAIL;
goto end; goto end;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment