ACLoader: Use enum for Surface flags

pull/3333/head
RichardTea 2020-07-17 11:23:50 +01:00
parent 719cc82a1f
commit 17b9403b7a
2 changed files with 29 additions and 16 deletions

View File

@ -471,32 +471,33 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
++node->mNumMeshes; ++node->mNumMeshes;
} }
switch ((*it).flags & 0xf) { switch ((*it).GetType()) {
// closed line // closed line
case 0x1: case Surface::ClosedLine:
needMat[idx].first += (unsigned int)(*it).entries.size(); needMat[idx].first += (unsigned int)(*it).entries.size();
needMat[idx].second += (unsigned int)(*it).entries.size() << 1u; needMat[idx].second += (unsigned int)(*it).entries.size() << 1u;
break; break;
// unclosed line // unclosed line
case 0x2: case Surface::OpenLine:
needMat[idx].first += (unsigned int)(*it).entries.size() - 1; needMat[idx].first += (unsigned int)(*it).entries.size() - 1;
needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u;
break; break;
// triangle strip // triangle strip
case 0x4: case Surface::TriangleStrip:
needMat[idx].first += (unsigned int)(*it).entries.size() - 2; needMat[idx].first += (unsigned int)(*it).entries.size() - 2;
needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3; needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3;
break; break;
// 0 == polygon, else unknown
default: default:
if ((*it).flags & 0xf) { // Coerce unknowns to a polygon and warn
ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown"); ASSIMP_LOG_WARN_F("AC3D: The type flag of a surface is unknown: ", (*it).flags);
(*it).flags &= ~(0xf); (*it).flags &= ~(Surface::Mask);
} // fallthrough
// polygon
case Surface::Polygon:
// the number of faces increments by one, the number // the number of faces increments by one, the number
// of vertices by surface.numref. // of vertices by surface.numref.
needMat[idx].first++; needMat[idx].first++;
@ -552,8 +553,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
const Surface &src = *it; const Surface &src = *it;
// closed polygon // closed polygon
unsigned int type = (*it).flags & 0xf; uint8_t type = (*it).GetType();
if (!type) { if (type == Surface::Polygon) {
aiFace &face = *faces++; aiFace &face = *faces++;
face.mNumIndices = (unsigned int)src.entries.size(); face.mNumIndices = (unsigned int)src.entries.size();
if (0 != face.mNumIndices) { if (0 != face.mNumIndices) {
@ -576,7 +577,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
} }
} }
} }
} else if (type == 0x4) { } else if (type == Surface::TriangleStrip) {
for (unsigned int i = 0; i < (unsigned int)src.entries.size() - 2; ++i) { for (unsigned int i = 0; i < (unsigned int)src.entries.size() - 2; ++i) {
const Surface::SurfaceEntry &entry1 = src.entries[i]; const Surface::SurfaceEntry &entry1 = src.entries[i];
const Surface::SurfaceEntry &entry2 = src.entries[i + 1]; const Surface::SurfaceEntry &entry2 = src.entries[i + 1];
@ -640,7 +641,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
// either a closed or an unclosed line // either a closed or an unclosed line
unsigned int tmp = (unsigned int)(*it).entries.size(); unsigned int tmp = (unsigned int)(*it).entries.size();
if (0x2 == type) --tmp; if (Surface::OpenLine == type) --tmp;
for (unsigned int m = 0; m < tmp; ++m) { for (unsigned int m = 0; m < tmp; ++m) {
aiFace &face = *faces++; aiFace &face = *faces++;
@ -663,7 +664,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
++uv; ++uv;
} }
if (0x1 == type && tmp - 1 == m) { if (Surface::ClosedLine == type && tmp - 1 == m) {
// if this is a closed line repeat its beginning now // if this is a closed line repeat its beginning now
it2 = (*it).entries.begin(); it2 = (*it).entries.begin();
} else } else

View File

@ -106,6 +106,18 @@ public:
typedef std::pair<unsigned int, aiVector2D> SurfaceEntry; typedef std::pair<unsigned int, aiVector2D> SurfaceEntry;
std::vector<SurfaceEntry> entries; std::vector<SurfaceEntry> entries;
// Type is low nibble of flags
enum Type : uint8_t {
Polygon = 0x0,
ClosedLine = 0x1,
OpenLine = 0x2,
TriangleStrip = 0x4, // ACC extension (TORCS and Speed Dreams)
Mask = 0xf,
};
inline constexpr uint8_t GetType() const { return (flags & Mask); }
}; };
// Represents an AC3D object // Represents an AC3D object