1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 09:15:38 +00:00

Modernize NiUVData, NiLinesData, NiTriBasedGeomData

This commit is contained in:
Alexei Kotov 2023-09-03 16:52:10 +03:00
parent 384a398b62
commit fda6b0b4f8
4 changed files with 14 additions and 13 deletions

View file

@ -85,7 +85,7 @@ namespace Nif
{
NiGeometryData::read(nif);
mNumTriangles = nif->getUShort();
nif->read(mNumTriangles);
}
void NiTriShapeData::read(NIFStream* nif)
@ -150,15 +150,15 @@ namespace Nif
{
if (flags[i] & 1)
{
lines.emplace_back(i);
lines.emplace_back(i + 1);
mLines.emplace_back(i);
mLines.emplace_back(i + 1);
}
}
// If there are just two vertices, they can be connected twice. Probably isn't critical.
if (flags[num - 1] & 1)
{
lines.emplace_back(num - 1);
lines.emplace_back(0);
mLines.emplace_back(num - 1);
mLines.emplace_back(0);
}
}
@ -207,10 +207,10 @@ namespace Nif
void NiUVData::read(NIFStream* nif)
{
for (int i = 0; i < 4; i++)
for (FloatKeyMapPtr& keys : mKeyList)
{
mKeyList[i] = std::make_shared<FloatKeyMap>();
mKeyList[i]->read(nif);
keys = std::make_shared<FloatKeyMap>();
keys->read(nif);
}
}

View file

@ -47,7 +47,7 @@ namespace Nif
// Abstract
struct NiTriBasedGeomData : public NiGeometryData
{
size_t mNumTriangles;
uint16_t mNumTriangles;
void read(NIFStream* nif) override;
};
@ -71,7 +71,8 @@ namespace Nif
struct NiLinesData : public NiGeometryData
{
// Lines, series of indices that correspond to connected vertices.
std::vector<unsigned short> lines;
// NB: assumes <=65536 number of vertices
std::vector<uint16_t> mLines;
void read(NIFStream* nif) override;
};
@ -103,7 +104,7 @@ namespace Nif
struct NiUVData : public Record
{
FloatKeyMapPtr mKeyList[4];
std::array<FloatKeyMapPtr, 4> mKeyList;
void read(NIFStream* nif) override;
};

View file

@ -40,7 +40,7 @@ namespace
for (const osg::Vec3f& vertex : vertices)
mesh.findOrAddVertex(Misc::Convert::toBullet(vertex), false);
mesh.preallocateIndices(static_cast<int>(data.mNumTriangles * 3));
mesh.preallocateIndices(static_cast<int>(data.mNumTriangles) * 3);
}
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& data)

View file

@ -1458,7 +1458,7 @@ namespace NifOsg
if (niGeometryData->recType != Nif::RC_NiLinesData)
return;
auto data = static_cast<const Nif::NiLinesData*>(niGeometryData);
const auto& line = data->lines;
const auto& line = data->mLines;
if (line.empty())
return;
geometry->addPrimitiveSet(