X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Fsg_binobj.cxx;h=54f3b8debf5c3d7ec00f13b93f6e14b5b7f3874b;hb=bc9b3f6ff1fcc5caa67c07ad99f971c0faacf91a;hp=7a58321f14d827a72ffff0def645c84ee78861ca;hpb=db509f4075c956a90773916b78e15c05cca8d89e;p=simgear.git diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 7a58321f..54f3b8de 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); } } @@ -745,7 +752,9 @@ bool SGBinObject::write_bin_file(const SGPath& file) cout << "tex coords = " << texcoords.size() << endl; version = 10; - if (wgs84_nodes.size() < 0xffff) { + if ((wgs84_nodes.size() < 0xffff) && + (normals.size() < 0xffff) && + (texcoords.size() < 0xffff)) { version = 7; // use smaller indices if possible }