Rewrite BSVertexData loading and read FO4 geometry properly

macos_ci_fix
Alexei Kotov 1 year ago
parent 1e3da5516a
commit 18e4af04b3

@ -433,60 +433,63 @@ namespace Nif
void BSVertexData::read(NIFStream* nif, uint16_t flags) void BSVertexData::read(NIFStream* nif, uint16_t flags)
{ {
uint16_t vertexFlag = flags & BSVertexDesc::VertexAttribute::Vertex; bool fullPrecision = true;
uint16_t tangentsFlag = flags & BSVertexDesc::VertexAttribute::Tangents; if (nif->getBethVersion() != NIFFile::BethVersion::BETHVER_SSE)
uint16_t UVsFlag = flags & BSVertexDesc::VertexAttribute::UVs; fullPrecision = flags & BSVertexDesc::VertexAttribute::Full_Precision;
uint16_t normalsFlag = flags & BSVertexDesc::VertexAttribute::Normals;
bool hasVertex = flags & BSVertexDesc::VertexAttribute::Vertex;
if (vertexFlag == BSVertexDesc::VertexAttribute::Vertex) bool hasTangent = flags & BSVertexDesc::VertexAttribute::Tangents;
{ bool hasUV = flags & BSVertexDesc::VertexAttribute::UVs;
nif->read(mVertex); bool hasNormal = flags & BSVertexDesc::VertexAttribute::Normals;
} bool hasVertexColor = flags & BSVertexDesc::VertexAttribute::Vertex_Colors;
bool hasSkinData = flags & BSVertexDesc::VertexAttribute::Skinned;
if ((vertexFlag | tangentsFlag) bool hasEyeData = flags & BSVertexDesc::VertexAttribute::Eye_Data;
== (BSVertexDesc::VertexAttribute::Vertex | BSVertexDesc::VertexAttribute::Tangents))
if (hasVertex)
{ {
nif->read(mBitangentX); if (fullPrecision)
} {
nif->read(mVertex);
if ((vertexFlag | tangentsFlag) == BSVertexDesc::VertexAttribute::Vertex) if (hasTangent)
{ nif->read(mBitangentX);
nif->read(mUnusedW); 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); nif->readArray(mUV);
}
if (normalsFlag) if (hasNormal)
{ {
nif->readArray(mNormal); nif->readArray(mNormal);
nif->read(mBitangentY); nif->read(mBitangentY);
if (hasTangent)
{
nif->readArray(mTangent);
nif->read(mBitangentZ);
}
} }
if ((normalsFlag | tangentsFlag) if (hasVertexColor)
== (BSVertexDesc::VertexAttribute::Normals | BSVertexDesc::VertexAttribute::Tangents)) nif->readArray(mVertColor);
{
nif->readArray(mTangent);
nif->read(mBitangentZ);
}
if (flags & BSVertexDesc::VertexAttribute::Vertex_Colors)
{
nif->readArray(mVertColors);
}
if (flags & BSVertexDesc::VertexAttribute::Skinned) if (hasSkinData)
{ {
nif->readArray(mBoneWeights); nif->readArray(mBoneWeights);
nif->readArray(mBoneIndices); nif->readArray(mBoneIndices);
} }
if (flags & BSVertexDesc::VertexAttribute::Eye_Data) if (hasEyeData)
{
nif->read(mEyeData); nif->read(mEyeData);
}
} }
void BSValueNode::read(NIFStream* nif) void BSValueNode::read(NIFStream* nif)

@ -339,14 +339,15 @@ namespace Nif
struct BSVertexData struct BSVertexData
{ {
osg::Vec3f mVertex; osg::Vec3f mVertex;
std::array<Misc::float16_t, 3> mHalfVertex;
float mBitangentX; float mBitangentX;
uint32_t mUnusedW; Misc::float16_t mHalfBitangentX;
std::array<Misc::float16_t, 2> mUV; std::array<Misc::float16_t, 2> mUV;
std::array<char, 3> mNormal; std::array<char, 3> mNormal;
char mBitangentY; char mBitangentY;
std::array<char, 3> mTangent; std::array<char, 3> mTangent;
char mBitangentZ; char mBitangentZ;
std::array<char, 4> mVertColors; std::array<char, 4> mVertColor;
std::array<Misc::float16_t, 4> mBoneWeights; std::array<Misc::float16_t, 4> mBoneWeights;
std::array<char, 4> mBoneIndices; std::array<char, 4> mBoneIndices;
float mEyeData; float mEyeData;

Loading…
Cancel
Save