ACLoader: Use enum for Surface flags
parent
719cc82a1f
commit
17b9403b7a
|
@ -471,32 +471,33 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
++node->mNumMeshes;
|
||||
}
|
||||
|
||||
switch ((*it).flags & 0xf) {
|
||||
switch ((*it).GetType()) {
|
||||
// closed line
|
||||
case 0x1:
|
||||
case Surface::ClosedLine:
|
||||
needMat[idx].first += (unsigned int)(*it).entries.size();
|
||||
needMat[idx].second += (unsigned int)(*it).entries.size() << 1u;
|
||||
break;
|
||||
|
||||
// unclosed line
|
||||
case 0x2:
|
||||
case Surface::OpenLine:
|
||||
needMat[idx].first += (unsigned int)(*it).entries.size() - 1;
|
||||
needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u;
|
||||
break;
|
||||
|
||||
// triangle strip
|
||||
case 0x4:
|
||||
case Surface::TriangleStrip:
|
||||
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) {
|
||||
ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown");
|
||||
(*it).flags &= ~(0xf);
|
||||
}
|
||||
// Coerce unknowns to a polygon and warn
|
||||
ASSIMP_LOG_WARN_F("AC3D: The type flag of a surface is unknown: ", (*it).flags);
|
||||
(*it).flags &= ~(Surface::Mask);
|
||||
// fallthrough
|
||||
|
||||
// polygon
|
||||
case Surface::Polygon:
|
||||
// the number of faces increments by one, the number
|
||||
// of vertices by surface.numref.
|
||||
needMat[idx].first++;
|
||||
|
@ -552,8 +553,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
const Surface &src = *it;
|
||||
|
||||
// closed polygon
|
||||
unsigned int type = (*it).flags & 0xf;
|
||||
if (!type) {
|
||||
uint8_t type = (*it).GetType();
|
||||
if (type == Surface::Polygon) {
|
||||
aiFace &face = *faces++;
|
||||
face.mNumIndices = (unsigned int)src.entries.size();
|
||||
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) {
|
||||
const Surface::SurfaceEntry &entry1 = src.entries[i];
|
||||
const Surface::SurfaceEntry &entry2 = src.entries[i + 1];
|
||||
|
@ -640,7 +641,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
|
||||
// either a closed or an unclosed line
|
||||
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) {
|
||||
aiFace &face = *faces++;
|
||||
|
||||
|
@ -663,7 +664,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
++uv;
|
||||
}
|
||||
|
||||
if (0x1 == type && tmp - 1 == m) {
|
||||
if (Surface::ClosedLine == type && tmp - 1 == m) {
|
||||
// if this is a closed line repeat its beginning now
|
||||
it2 = (*it).entries.begin();
|
||||
} else
|
||||
|
|
|
@ -106,6 +106,18 @@ public:
|
|||
|
||||
typedef std::pair<unsigned int, aiVector2D> SurfaceEntry;
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue