Skip to content

Commit

Permalink
Merge branch 'nifcouriersix' into 'master'
Browse files Browse the repository at this point in the history
Modernize NIF loader, part 6

See merge request OpenMW/openmw!3435
  • Loading branch information
psi29a committed Sep 19, 2023
2 parents 1a5b634 + 82eed09 commit 3ae189d
Show file tree
Hide file tree
Showing 10 changed files with 871 additions and 568 deletions.
4 changes: 2 additions & 2 deletions apps/niftest/niftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool isNIF(const std::filesystem::path& filename)
/// See if the file has the "bsa" extension.
bool isBSA(const std::filesystem::path& filename)
{
return hasExtension(filename, ".bsa");
return hasExtension(filename, ".bsa") || hasExtension(filename, ".ba2");
}

std::unique_ptr<VFS::Archive> makeBsaArchive(const std::filesystem::path& path)
Expand Down Expand Up @@ -216,7 +216,7 @@ int main(int argc, char** argv)
else
{
std::cerr << "ERROR: \"" << Files::pathToUnicodeString(path)
<< "\" is not a nif file, bsa file, or directory!" << std::endl;
<< "\" is not a nif file, bsa/ba2 file, or directory!" << std::endl;
}
}
catch (std::exception& e)
Expand Down
10 changes: 5 additions & 5 deletions apps/openmw_test_suite/nifosg/testnifloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ osg::Group {
init(node);
Nif::BSShaderPPLightingProperty property;
property.recType = Nif::RC_BSShaderPPLightingProperty;
property.textureSet = nullptr;
property.mTextureSet = nullptr;
property.mController = nullptr;
property.type = GetParam().mShaderType;
node.mProperties.push_back(Nif::RecordPtrT<Nif::Property>(&property));
property.mType = GetParam().mShaderType;
node.mProperties.push_back(Nif::RecordPtrT<Nif::NiProperty>(&property));
Nif::NIFFile file("test.nif");
file.mRoots.push_back(&node);
auto result = Loader::load(file, &mImageManager);
Expand All @@ -217,8 +217,8 @@ osg::Group {
property.recType = Nif::RC_BSLightingShaderProperty;
property.mTextureSet = nullptr;
property.mController = nullptr;
property.type = GetParam().mShaderType;
node.mProperties.push_back(Nif::RecordPtrT<Nif::Property>(&property));
property.mType = GetParam().mShaderType;
node.mProperties.push_back(Nif::RecordPtrT<Nif::NiProperty>(&property));
Nif::NIFFile file("test.nif");
file.mRoots.push_back(&node);
auto result = Loader::load(file, &mImageManager);
Expand Down
18 changes: 9 additions & 9 deletions components/nif/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ namespace Nif
{
NiDynamicEffect::read(nif);

mDimmer = nif->getFloat();
mAmbient = nif->getVector3();
mDiffuse = nif->getVector3();
mSpecular = nif->getVector3();
nif->read(mDimmer);
nif->read(mAmbient);
nif->read(mDiffuse);
nif->read(mSpecular);
}

void NiPointLight::read(NIFStream* nif)
{
NiLight::read(nif);

mConstantAttenuation = nif->getFloat();
mLinearAttenuation = nif->getFloat();
mQuadraticAttenuation = nif->getFloat();
nif->read(mConstantAttenuation);
nif->read(mLinearAttenuation);
nif->read(mQuadraticAttenuation);
}

void NiSpotLight::read(NIFStream* nif)
{
NiPointLight::read(nif);

mCutoff = nif->getFloat();
mExponent = nif->getFloat();
nif->read(mCutoff);
nif->read(mExponent);
}

void NiTextureEffect::read(NIFStream* nif)
Expand Down
10 changes: 0 additions & 10 deletions components/nif/nifstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,6 @@ namespace Nif

/// Read a sequence of null-terminated strings
std::string getStringPalette();

/// DEPRECATED: Use read() or get()
char getChar() { return get<char>(); }
unsigned short getUShort() { return get<unsigned short>(); }
int getInt() { return get<int>(); }
unsigned int getUInt() { return get<unsigned int>(); }
float getFloat() { return get<float>(); }
osg::Vec2f getVector2() { return get<osg::Vec2f>(); }
osg::Vec3f getVector3() { return get<osg::Vec3f>(); }
osg::Vec4f getVector4() { return get<osg::Vec4f>(); }
};

template <>
Expand Down
77 changes: 40 additions & 37 deletions components/nif/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions components/nif/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace Nif
uint32_t mFlags;
NiTransform mTransform;
osg::Vec3f mVelocity;
PropertyList mProperties;
NiPropertyList mProperties;
BoundingVolume mBounds;
NiCollisionObjectPtr mCollision;
// Parent nodes for the node. Only types derived from NiNode can be parents.
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 3ae189d

Please sign in to comment.