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; diff --git a/components/nif/property.cpp b/components/nif/property.cpp index c0fc21fffa..a67b5d6121 100644 --- a/components/nif/property.cpp +++ b/components/nif/property.cpp @@ -227,10 +227,20 @@ namespace Nif emissiveMult = nif->getFloat(); } - void S_VertexColorProperty::read(NIFStream* nif) + void NiVertexColorProperty::read(NIFStream* nif) { - vertmode = nif->getInt(); - lightmode = nif->getInt(); + Property::read(nif); + mFlags = nif->getUShort(); + if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB) + { + mVertexMode = static_cast(nif->getUInt()); + mLightingMode = static_cast(nif->getUInt()); + } + else + { + mVertexMode = static_cast((mFlags >> 4) & 0x3); + mLightingMode = static_cast((mFlags >> 3) & 0x1); + } } void S_AlphaProperty::read(NIFStream* nif) diff --git a/components/nif/property.hpp b/components/nif/property.hpp index 74b2711709..70a822d7eb 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -293,22 +293,6 @@ namespace Nif void read(NIFStream* nif); }; - struct S_VertexColorProperty - { - /* Vertex mode: - 0 - source ignore - 1 - source emmisive - 2 - source amb diff - - Lighting mode - 0 - lighting emmisive - 1 - lighting emmisive ambient/diffuse - */ - int vertmode, lightmode; - - void read(NIFStream* nif); - }; - struct S_AlphaProperty { /* @@ -402,9 +386,28 @@ namespace Nif int alphaTestMode() const { return (flags >> 10) & 0x7; } }; - struct NiVertexColorProperty : public StructPropT + struct NiVertexColorProperty : public Property { + enum class VertexMode : unsigned int + { + VertMode_SrcIgnore = 0, + VertMode_SrcEmissive = 1, + VertMode_SrcAmbDif = 2 + }; + + enum class LightMode : unsigned int + { + LightMode_Emissive = 0, + LightMode_EmiAmbDif = 1 + }; + + unsigned short mFlags; + VertexMode mVertexMode; + LightMode mLightingMode; + + void read(NIFStream* nif) override; }; + struct NiStencilProperty : public Property { S_StencilProperty data; diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 2ad7a7ef09..eaf49bb61d 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -2300,23 +2300,39 @@ namespace NifOsg { const Nif::NiVertexColorProperty* vertprop = static_cast(property); - lightmode = vertprop->data.lightmode; - switch (vertprop->data.vertmode) + switch (vertprop->mVertexMode) { - case 0: + case Nif::NiVertexColorProperty::VertexMode::VertMode_SrcIgnore: + { mat->setColorMode(osg::Material::OFF); break; - case 1: + } + case Nif::NiVertexColorProperty::VertexMode::VertMode_SrcEmissive: + { mat->setColorMode(osg::Material::EMISSION); break; - case 2: - if (lightmode != 0) - mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - else - mat->setColorMode(osg::Material::OFF); + } + case Nif::NiVertexColorProperty::VertexMode::VertMode_SrcAmbDif: + { + switch (vertprop->mLightingMode) + { + case Nif::NiVertexColorProperty::LightMode::LightMode_Emissive: + { + mat->setColorMode(osg::Material::OFF); + break; + } + case Nif::NiVertexColorProperty::LightMode::LightMode_EmiAmbDif: + default: + { + mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); + break; + } + } break; + } } + break; } case Nif::RC_NiAlphaProperty: