From d39127cc3d2e28d86b90a070647c6ac49cb6a44b Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Fri, 10 Feb 2023 23:06:56 +0300 Subject: [PATCH] Add NiTriBasedGeomData abstraction --- components/nif/data.cpp | 14 ++++++++------ components/nif/data.hpp | 14 ++++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 3fb38bcec2..fac41518c9 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -118,14 +118,18 @@ namespace Nif nif->skip(4); // Additional data } - void NiTriShapeData::read(NIFStream* nif) + void NiTriBasedGeomData::read(NIFStream* nif) { NiGeometryData::read(nif); + mNumTriangles = nif->getUShort(); + } - /*int tris =*/nif->getUShort(); + void NiTriShapeData::read(NIFStream* nif) + { + NiTriBasedGeomData::read(nif); // We have three times as many vertices as triangles, so this - // is always equal to tris*3. + // is always equal to mNumTriangles * 3. int cnt = nif->getInt(); bool hasTriangles = true; if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD) @@ -147,9 +151,7 @@ namespace Nif void NiTriStripsData::read(NIFStream* nif) { - NiGeometryData::read(nif); - - mNumTriangles = nif->getUShort(); + NiTriBasedGeomData::read(nif); // Number of triangle strips int numStrips = nif->getUShort(); diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 563007f73f..bac47a87f5 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -43,7 +43,15 @@ namespace Nif void read(NIFStream* nif) override; }; - struct NiTriShapeData : public NiGeometryData + // Abstract + struct NiTriBasedGeomData : public NiGeometryData + { + size_t mNumTriangles; + + void read(NIFStream* nif) override; + }; + + struct NiTriShapeData : public NiTriBasedGeomData { // Triangles, three vertex indices per triangle std::vector triangles; @@ -51,10 +59,8 @@ namespace Nif void read(NIFStream* nif) override; }; - struct NiTriStripsData : public NiGeometryData + struct NiTriStripsData : public NiTriBasedGeomData { - size_t mNumTriangles; - // Triangle strips, series of vertex indices. std::vector> strips;