From f0160d387af00eb034f8a8af96dec053a8e29683 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 2 Jun 2005 09:02:55 +0000 Subject: [PATCH] fix two severe geometry bugs in the zym loader git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5375 d7cf8633-e32d-0410-b094-e92efae38249 --- model_alias.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/model_alias.c b/model_alias.c index 2d25e27b..d869e14f 100644 --- a/model_alias.c +++ b/model_alias.c @@ -70,6 +70,8 @@ void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const frameblend_t *frameb float lerp1, lerp2, lerp3, lerp4; const float *vertsbase, *verts1, *verts2, *verts3, *verts4; // vertex morph + if (!mesh->data_morphvertex3f) + Host_Error("model %s has no skeletal or vertex morph animation data\n", model->name); vertsbase = mesh->data_morphvertex3f; vertcount = mesh->num_vertices; verts1 = vertsbase + frameblend[0].frame * vertcount * 3; @@ -1344,6 +1346,8 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer) || (unsigned int)outelements[1] >= (unsigned int)pheader->numverts || (unsigned int)outelements[2] >= (unsigned int)pheader->numverts) Host_Error("%s corrupt renderlist (out of bounds index)\n", loadmodel->name); + if (vertbonecounts[outelements[0]] == 0 || vertbonecounts[outelements[1]] == 0 || vertbonecounts[outelements[2]] == 0) + Host_Error("%s corrupt renderlist (references vertex with no bone weights\n", loadmodel->name); renderlist += 3; outelements += 3; } @@ -1362,14 +1366,14 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer) } } mesh->num_vertexboneweights = 0; - for (j = 0;j < mesh->num_vertices;j++) + for (j = 0;j < pheader->numverts;j++) if (remapvertices[j] >= 0) mesh->num_vertexboneweights += vertbonecounts[remapvertices[j]]; mesh->data_vertexboneweights = Mem_Alloc(loadmodel->mempool, mesh->num_vertexboneweights * sizeof(surfmeshvertexboneweight_t)); mesh->num_vertexboneweights = 0; // note this vertexboneweight ordering requires that the remapvertices array is sequential numbers (separated by -1 values for omitted vertices) l = 0; - for (j = 0;j < mesh->num_vertices;j++) + for (j = 0;j < pheader->numverts;j++) { if (remapvertices[j] < 0) { @@ -1389,20 +1393,19 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer) l++; } } - - Mod_ValidateElements(mesh->data_element3i, mesh->num_triangles, mesh->num_vertices, __FILE__, __LINE__); - Mod_BuildTriangleNeighbors(mesh->data_neighbor3i, mesh->data_element3i, mesh->num_triangles); - Mod_Alias_Mesh_CompileFrameZero(mesh); - + shadername = (char *) (pheader->lump_shaders.start + pbase) + i * 32; // since zym models do not have named sections, reuse their shader // name as the section name - shadername = (char *) (pheader->lump_shaders.start + pbase) + i * 32; if (shadername[0]) Mod_BuildAliasSkinsFromSkinFiles(loadmodel->data_textures + i, skinfiles, shadername, shadername); else for (j = 0;j < loadmodel->numskins;j++) Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + i + j * loadmodel->num_surfaces, NULL); + Mod_ValidateElements(mesh->data_element3i, mesh->num_triangles, mesh->num_vertices, __FILE__, __LINE__); + Mod_BuildTriangleNeighbors(mesh->data_neighbor3i, mesh->data_element3i, mesh->num_triangles); + Mod_Alias_Mesh_CompileFrameZero(mesh); + surface = loadmodel->data_surfaces + i; surface->groupmesh = mesh; surface->texture = loadmodel->data_textures + i; -- 2.39.2