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)
{
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)

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

Loading…
Cancel
Save