Commit b6b6561a authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

d3dx9/mesh: Split skin header and weights parse functions.

They don't really share any code in common. Signed-off-by: 's avatarMatteo Bruni <mbruni@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 8537db02
...@@ -3117,55 +3117,69 @@ end: ...@@ -3117,55 +3117,69 @@ end:
return hr; return hr;
} }
static HRESULT parse_skin_mesh_info(ID3DXFileData *filedata, struct mesh_data *mesh_data, DWORD index) static HRESULT parse_skin_mesh_header(ID3DXFileData *filedata, struct mesh_data *mesh_data)
{ {
HRESULT hr;
SIZE_T data_size;
const BYTE *data; const BYTE *data;
SIZE_T data_size;
HRESULT hr;
TRACE("(%p, %p, %u)\n", filedata, mesh_data, index); TRACE("filedata %p, mesh_data %p.\n", filedata, mesh_data);
hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void**)&data);
if (FAILED(hr)) return hr;
hr = E_FAIL; if (FAILED(hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data)))
return hr;
if (!mesh_data->skin_info) { if (data_size < sizeof(WORD) * 3)
if (data_size < sizeof(WORD) * 3) { {
WARN("truncated data (%ld bytes)\n", data_size); WARN("Truncated data (%Id bytes).\n", data_size);
goto end; filedata->lpVtbl->Unlock(filedata);
return E_FAIL;
} }
/* Skip nMaxSkinWeightsPerVertex and nMaxSkinWeightsPerFace */ /* Skip nMaxSkinWeightsPerVertex and nMaxSkinWeightsPerFace */
data += 2 * sizeof(WORD); data += 2 * sizeof(WORD);
mesh_data->bone_count = *(WORD*)data; mesh_data->bone_count = *(WORD *)data;
hr = D3DXCreateSkinInfoFVF(mesh_data->num_vertices, mesh_data->fvf, mesh_data->bone_count, &mesh_data->skin_info); hr = D3DXCreateSkinInfoFVF(mesh_data->num_vertices, mesh_data->fvf, mesh_data->bone_count,
} else { &mesh_data->skin_info);
return hr;
}
static HRESULT parse_skin_weights_info(ID3DXFileData *filedata, struct mesh_data *mesh_data, unsigned int index)
{
unsigned int influence_count;
const char *name; const char *name;
DWORD nb_influences; const BYTE *data;
SIZE_T data_size;
HRESULT hr;
/* FIXME: String must be retrieved directly instead of through a pointer once ID3DXFILE is fixed */ TRACE("filedata %p, mesh_data %p, index %u.\n", filedata, mesh_data, index);
name = *(const char**)data;
data += sizeof(char*); if (FAILED(hr = filedata->lpVtbl->Lock(filedata, &data_size, (const void **)&data)))
return hr;
nb_influences = *(DWORD*)data; /* FIXME: String will have to be retrieved directly instead of through a
data += sizeof(DWORD); * pointer once our ID3DXFileData implementation is fixed. */
name = *(const char **)data;
data += sizeof(char *);
if (data_size < (sizeof(char*) + sizeof(DWORD) + nb_influences * (sizeof(DWORD) + sizeof(FLOAT)) + 16 * sizeof(FLOAT))) { influence_count = *(uint32_t *)data;
WARN("truncated data (%ld bytes)\n", data_size); data += sizeof(uint32_t);
goto end;
if (data_size < (sizeof(char *) + sizeof(uint32_t) + influence_count * (sizeof(uint32_t) + sizeof(float))
+ 16 * sizeof(float)))
{
WARN("Truncated data (%Id bytes).\n", data_size);
filedata->lpVtbl->Unlock(filedata);
return E_FAIL;
} }
hr = mesh_data->skin_info->lpVtbl->SetBoneName(mesh_data->skin_info, index, name); hr = mesh_data->skin_info->lpVtbl->SetBoneName(mesh_data->skin_info, index, name);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = mesh_data->skin_info->lpVtbl->SetBoneInfluence(mesh_data->skin_info, index, nb_influences, hr = mesh_data->skin_info->lpVtbl->SetBoneInfluence(mesh_data->skin_info, index, influence_count,
(const DWORD*)data, (const FLOAT*)(data + nb_influences * sizeof(DWORD))); (const DWORD *)data, (const float *)(data + influence_count * sizeof(uint32_t)));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
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 + nb_influences * (sizeof(DWORD) + sizeof(FLOAT)))); (const D3DMATRIX *)(data + influence_count * (sizeof(uint32_t) + sizeof(float))));
}
end:
filedata->lpVtbl->Unlock(filedata);
return hr; return hr;
} }
...@@ -3317,7 +3331,7 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, ...@@ -3317,7 +3331,7 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data,
hr = E_FAIL; hr = E_FAIL;
goto end; goto end;
} }
hr = parse_skin_mesh_info(child, mesh_data, 0); hr = parse_skin_mesh_header(child, mesh_data);
if (FAILED(hr)) if (FAILED(hr))
goto end; goto end;
} else if (IsEqualGUID(&type, &DXFILEOBJ_SkinWeights)) { } else if (IsEqualGUID(&type, &DXFILEOBJ_SkinWeights)) {
...@@ -3326,7 +3340,7 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data, ...@@ -3326,7 +3340,7 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data,
hr = E_FAIL; hr = E_FAIL;
goto end; goto end;
} }
hr = parse_skin_mesh_info(child, mesh_data, skin_weights_info_count); hr = parse_skin_weights_info(child, mesh_data, skin_weights_info_count);
if (FAILED(hr)) if (FAILED(hr))
goto end; goto end;
skin_weights_info_count++; skin_weights_info_count++;
......
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