From 6c29247180dc247fb9a1d9bc17cb55ce9a20bb14 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 6 Jul 2020 17:41:14 -0400 Subject: [PATCH] add triangle strip support to AC file loader --- code/AssetLib/AC/ACLoader.cpp | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/code/AssetLib/AC/ACLoader.cpp b/code/AssetLib/AC/ACLoader.cpp index ac1631a9b..6be720f02 100644 --- a/code/AssetLib/AC/ACLoader.cpp +++ b/code/AssetLib/AC/ACLoader.cpp @@ -484,6 +484,12 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; break; + // triangle strip + case 0x4: + needMat[idx].first += (unsigned int)(*it).entries.size() - 2; + needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3; + break; + // 0 == polygon, else unknown default: if ((*it).flags & 0xf) { @@ -570,6 +576,61 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, } } } + } else if (type == 0x4) { + for (unsigned int i = 0; i < (unsigned int)src.entries.size() - 2; ++i) { + const Surface::SurfaceEntry &entry1 = src.entries[i]; + const Surface::SurfaceEntry &entry2 = src.entries[i + 1]; + const Surface::SurfaceEntry &entry3 = src.entries[i + 2]; + + // skip degenerate triangles + if (object.vertices[entry1.first] == object.vertices[entry2.first] || + object.vertices[entry1.first] == object.vertices[entry3.first] || + object.vertices[entry2.first] == object.vertices[entry3.first]) { + mesh->mNumFaces--; + mesh->mNumVertices -= 3; + continue; + } + + aiFace &face = *faces++; + face.mNumIndices = 3; + face.mIndices = new unsigned int[face.mNumIndices]; + face.mIndices[0] = cur++; + face.mIndices[1] = cur++; + face.mIndices[2] = cur++; + if (!(i & 1)) { + *vertices++ = object.vertices[entry1.first] + object.translation; + if (uv) { + uv->x = entry1.second.x; + uv->y = entry1.second.y; + ++uv; + } + *vertices++ = object.vertices[entry2.first] + object.translation; + if (uv) { + uv->x = entry2.second.x; + uv->y = entry2.second.y; + ++uv; + } + } else { + *vertices++ = object.vertices[entry2.first] + object.translation; + if (uv) { + uv->x = entry2.second.x; + uv->y = entry2.second.y; + ++uv; + } + *vertices++ = object.vertices[entry1.first] + object.translation; + if (uv) { + uv->x = entry1.second.x; + uv->y = entry1.second.y; + ++uv; + } + } + *vertices++ = object.vertices[entry3.first] + object.translation; + if (uv) { + uv->x = entry3.second.x; + uv->y = entry3.second.y; + ++uv; + } + } } else { it2 = (*it).entries.begin();