From: James Turner Date: Wed, 12 Oct 2011 16:01:52 +0000 (+0100) Subject: Fix BTG writer for non-included index arrays. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;ds=sidebyside;h=e4e31be7d43569a92a5d9fa7e784381b66cbd95a;p=simgear.git Fix BTG writer for non-included index arrays. --- diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 7a58321f..e01a5286 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -261,13 +261,13 @@ void write_indices(gzFile fp, unsigned char indexMask, for (unsigned int i=0; i < count; ++i) { write_indice(fp, static_cast(vertices[i])); - if (!normals.empty()) { + if (indexMask & SG_IDX_NORMALS) { write_indice(fp, static_cast(normals[i])); } - if (!colors.empty()) { + if (indexMask & SG_IDX_COLORS) { write_indice(fp, static_cast(colors[i])); } - if (!texCoords.empty()) { + if (indexMask & SG_IDX_TEXCOORDS) { write_indice(fp, static_cast(texCoords[i])); } } @@ -667,6 +667,8 @@ void SGBinObject::write_objects(gzFile fp, int type, const group_list& verts, unsigned int start = 0, end = 1; string m; + int_list emptyList; + while (start < materials.size()) { m = materials[start]; // find range of objects with identical material, write out as a single object @@ -692,10 +694,15 @@ void SGBinObject::write_objects(gzFile fp, int type, const group_list& verts, // cout << "material:" << m << ", count =" << count << endl; // elements for (unsigned int i=start; i < end; ++i) { + const int_list& va(verts[i]); + const int_list& na((idx_mask & SG_IDX_NORMALS) ? normals[i] : emptyList); + const int_list& ca((idx_mask & SG_IDX_COLORS) ? colors[i] : emptyList); + const int_list& tca((idx_mask & SG_IDX_TEXCOORDS) ? texCoords[i] : emptyList); + if (version == 7) { - write_indices(fp, idx_mask, verts[i], normals[i], colors[i], texCoords[i]); + write_indices(fp, idx_mask, va, na, ca, tca); } else { - write_indices(fp, idx_mask, verts[i], normals[i], colors[i], texCoords[i]); + write_indices(fp, idx_mask, va, na, ca, tca); } }