diff --git a/components/nif/node.cpp b/components/nif/node.cpp index 328546b7c6..ac99a06a1b 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -433,60 +433,63 @@ namespace Nif void BSVertexData::read(NIFStream* nif, uint16_t flags) { - uint16_t vertexFlag = flags & BSVertexDesc::VertexAttribute::Vertex; - uint16_t tangentsFlag = flags & BSVertexDesc::VertexAttribute::Tangents; - uint16_t UVsFlag = flags & BSVertexDesc::VertexAttribute::UVs; - uint16_t normalsFlag = flags & BSVertexDesc::VertexAttribute::Normals; - - if (vertexFlag == BSVertexDesc::VertexAttribute::Vertex) - { - nif->read(mVertex); - } - - if ((vertexFlag | tangentsFlag) - == (BSVertexDesc::VertexAttribute::Vertex | BSVertexDesc::VertexAttribute::Tangents)) + bool fullPrecision = true; + if (nif->getBethVersion() != NIFFile::BethVersion::BETHVER_SSE) + fullPrecision = flags & BSVertexDesc::VertexAttribute::Full_Precision; + + bool hasVertex = flags & BSVertexDesc::VertexAttribute::Vertex; + bool hasTangent = flags & BSVertexDesc::VertexAttribute::Tangents; + bool hasUV = flags & BSVertexDesc::VertexAttribute::UVs; + bool hasNormal = flags & BSVertexDesc::VertexAttribute::Normals; + bool hasVertexColor = flags & BSVertexDesc::VertexAttribute::Vertex_Colors; + bool hasSkinData = flags & BSVertexDesc::VertexAttribute::Skinned; + bool hasEyeData = flags & BSVertexDesc::VertexAttribute::Eye_Data; + + if (hasVertex) { - nif->read(mBitangentX); - } - - if ((vertexFlag | tangentsFlag) == BSVertexDesc::VertexAttribute::Vertex) - { - nif->read(mUnusedW); + if (fullPrecision) + { + nif->read(mVertex); + if (hasTangent) + nif->read(mBitangentX); + else + nif->skip(4); // Unused + } + else + { + nif->readArray(mHalfVertex); + if (hasTangent) + nif->read(mHalfBitangentX); + else + nif->skip(2); // Unused + } } - if (UVsFlag == BSVertexDesc::VertexAttribute::UVs) - { + if (hasUV) nif->readArray(mUV); - } - if (normalsFlag) + if (hasNormal) { nif->readArray(mNormal); nif->read(mBitangentY); + if (hasTangent) + { + nif->readArray(mTangent); + nif->read(mBitangentZ); + } } - if ((normalsFlag | tangentsFlag) - == (BSVertexDesc::VertexAttribute::Normals | BSVertexDesc::VertexAttribute::Tangents)) - { - nif->readArray(mTangent); - nif->read(mBitangentZ); - } - - if (flags & BSVertexDesc::VertexAttribute::Vertex_Colors) - { - nif->readArray(mVertColors); - } + if (hasVertexColor) + nif->readArray(mVertColor); - if (flags & BSVertexDesc::VertexAttribute::Skinned) + if (hasSkinData) { nif->readArray(mBoneWeights); nif->readArray(mBoneIndices); } - if (flags & BSVertexDesc::VertexAttribute::Eye_Data) - { + if (hasEyeData) nif->read(mEyeData); - } } void BSValueNode::read(NIFStream* nif) diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 7d851051e0..c87c3f6a62 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -339,14 +339,15 @@ namespace Nif struct BSVertexData { osg::Vec3f mVertex; + std::array mHalfVertex; float mBitangentX; - uint32_t mUnusedW; + Misc::float16_t mHalfBitangentX; std::array mUV; std::array mNormal; char mBitangentY; std::array mTangent; char mBitangentZ; - std::array mVertColors; + std::array mVertColor; std::array mBoneWeights; std::array mBoneIndices; float mEyeData;