From b665fed8f29c28767fc4e768447500c768ea8614 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 14 May 2020 10:52:27 +0300 Subject: [PATCH] Introduce NiGeometry abstraction --- components/nif/data.cpp | 8 ++++---- components/nif/data.hpp | 8 ++++---- components/nif/node.hpp | 11 +++++++---- components/nifosg/nifloader.cpp | 13 ++----------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 2c5568397d..8ae49476b7 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -31,7 +31,7 @@ void NiSkinInstance::post(NIFFile *nif) } } -void ShapeData::read(NIFStream *nif) +void NiGeometryData::read(NIFStream *nif) { int verts = nif->getUShort(); @@ -69,7 +69,7 @@ void ShapeData::read(NIFStream *nif) void NiTriShapeData::read(NIFStream *nif) { - ShapeData::read(nif); + NiGeometryData::read(nif); /*int tris =*/ nif->getUShort(); @@ -92,7 +92,7 @@ void NiTriShapeData::read(NIFStream *nif) void NiTriStripsData::read(NIFStream *nif) { - ShapeData::read(nif); + NiGeometryData::read(nif); // Every strip with n points defines n-2 triangles, so this should be unnecessary. /*int tris =*/ nif->getUShort(); @@ -112,7 +112,7 @@ void NiTriStripsData::read(NIFStream *nif) void NiAutoNormalParticlesData::read(NIFStream *nif) { - ShapeData::read(nif); + NiGeometryData::read(nif); // Should always match the number of vertices numParticles = nif->getUShort(); diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 39901b5840..33818810a4 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -32,7 +32,7 @@ namespace Nif { // Common ancestor for several data classes -class ShapeData : public Record +class NiGeometryData : public Record { public: std::vector vertices, normals; @@ -44,7 +44,7 @@ public: void read(NIFStream *nif); }; -class NiTriShapeData : public ShapeData +class NiTriShapeData : public NiGeometryData { public: // Triangles, three vertex indices per triangle @@ -53,7 +53,7 @@ public: void read(NIFStream *nif); }; -class NiTriStripsData : public ShapeData +class NiTriStripsData : public NiGeometryData { public: // Triangle strips, series of vertex indices. @@ -62,7 +62,7 @@ public: void read(NIFStream *nif); }; -class NiAutoNormalParticlesData : public ShapeData +class NiAutoNormalParticlesData : public NiGeometryData { public: int numParticles; diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 71e66c53a4..06a1a3b76a 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -128,7 +128,12 @@ struct NiNode : Node } }; -struct NiTriShape : Node +struct NiGeometry : Node +{ + NiSkinInstancePtr skin; +}; + +struct NiTriShape : NiGeometry { /* Possible flags: 0x40 - mesh has no vertex normals ? @@ -138,7 +143,6 @@ struct NiTriShape : Node */ NiTriShapeDataPtr data; - NiSkinInstancePtr skin; void read(NIFStream *nif) { @@ -157,10 +161,9 @@ struct NiTriShape : Node } }; -struct NiTriStrips : Node +struct NiTriStrips : NiGeometry { NiTriStripsDataPtr data; - NiSkinInstancePtr skin; void read(NIFStream *nif) { diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 8d08ebef16..5217642740 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -649,11 +649,7 @@ namespace NifOsg const bool isMarker = hasMarkers && !nodeName.compare(0, markerName.size(), markerName); if (!isMarker && nodeName.compare(0, shadowName.size(), shadowName) && nodeName.compare(0, shadowName2.size(), shadowName2)) { - Nif::NiSkinInstancePtr skin; - if (nifNode->recType == Nif::RC_NiTriShape) - skin = static_cast(nifNode)->skin; - else // if (nifNode->recType == Nif::RC_NiTriStrips) - skin = static_cast(nifNode)->skin; + Nif::NiSkinInstancePtr skin = static_cast(nifNode)->skin; if (skin.empty()) handleTriShape(nifNode, node, composite, boundTextures, animflags); @@ -1294,12 +1290,7 @@ namespace NifOsg // Assign bone weights osg::ref_ptr map (new SceneUtil::RigGeometry::InfluenceMap); - Nif::NiSkinInstancePtr skinPtr; - if (nifNode->recType == Nif::RC_NiTriShape) - skinPtr = static_cast(nifNode)->skin; - else - skinPtr = static_cast(nifNode)->skin; - const Nif::NiSkinInstance *skin = skinPtr.getPtr(); + const Nif::NiSkinInstance *skin = static_cast(nifNode)->skin.getPtr(); const Nif::NiSkinData *data = skin->data.getPtr(); const Nif::NodeList &bones = skin->bones; for(size_t i = 0;i < bones.length();i++)