Skip to content

Commit

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

See merge request OpenMW/openmw!3418
  • Loading branch information
psi29a committed Sep 12, 2023
2 parents 9d186ee + 4dd2f34 commit 42b7734
Show file tree
Hide file tree
Showing 27 changed files with 603 additions and 641 deletions.
28 changes: 13 additions & 15 deletions apps/openmw_test_suite/nif/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@

namespace Nif::Testing
{
inline void init(Transformation& value)
inline void init(NiTransform& value)
{
value = Transformation::getIdentity();
value = NiTransform::getIdentity();
}

inline void init(Extra& value)
{
value.mNext = ExtraPtr(nullptr);
}

inline void init(Named& value)
inline void init(NiObjectNET& value)
{
value.extra = ExtraPtr(nullptr);
value.extralist = ExtraList();
value.controller = ControllerPtr(nullptr);
value.mExtra = ExtraPtr(nullptr);
value.mExtraList = ExtraList();
value.mController = ControllerPtr(nullptr);
}

inline void init(Node& value)
inline void init(NiAVObject& value)
{
init(static_cast<Named&>(value));
value.flags = 0;
init(value.trafo);
value.hasBounds = false;
value.isBone = false;
init(static_cast<NiObjectNET&>(value));
value.mFlags = 0;
init(value.mTransform);
}

inline void init(NiGeometry& value)
{
init(static_cast<Node&>(value));
init(static_cast<NiAVObject&>(value));
value.data = NiGeometryDataPtr(nullptr);
value.skin = NiSkinInstancePtr(nullptr);
}
Expand All @@ -54,7 +52,7 @@ namespace Nif::Testing
inline void init(NiSkinInstance& value)
{
value.mData = NiSkinDataPtr(nullptr);
value.mRoot = NodePtr(nullptr);
value.mRoot = NiAVObjectPtr(nullptr);
}

inline void init(Controller& value)
Expand All @@ -65,7 +63,7 @@ namespace Nif::Testing
value.phase = 0;
value.timeStart = 0;
value.timeStop = 0;
value.target = NamedPtr(nullptr);
value.target = NiObjectNETPtr(nullptr);
}
}

Expand Down
322 changes: 153 additions & 169 deletions apps/openmw_test_suite/nifloader/testbulletnifloader.cpp

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions apps/openmw_test_suite/nifosg/testnifloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace

TEST_F(NifOsgLoaderTest, shouldLoadFileWithDefaultNode)
{
Nif::Node node;
Nif::NiAVObject node;
init(node);
Nif::NIFFile file("test.nif");
file.mRoots.push_back(&node);
Expand Down Expand Up @@ -183,14 +183,14 @@ osg::Group {

TEST_P(NifOsgLoaderBSShaderPrefixTest, shouldAddShaderPrefix)
{
Nif::Node node;
Nif::NiAVObject node;
init(node);
Nif::BSShaderPPLightingProperty property;
property.recType = Nif::RC_BSShaderPPLightingProperty;
property.textureSet = nullptr;
property.controller = nullptr;
property.mController = nullptr;
property.type = GetParam().mShaderType;
node.props.push_back(Nif::RecordPtrT<Nif::Property>(&property));
node.mProperties.push_back(Nif::RecordPtrT<Nif::Property>(&property));
Nif::NIFFile file("test.nif");
file.mRoots.push_back(&node);
auto result = Loader::load(file, &mImageManager);
Expand All @@ -211,14 +211,14 @@ osg::Group {

TEST_P(NifOsgLoaderBSLightingShaderPrefixTest, shouldAddShaderPrefix)
{
Nif::Node node;
Nif::NiAVObject node;
init(node);
Nif::BSLightingShaderProperty property;
property.recType = Nif::RC_BSLightingShaderProperty;
property.mTextureSet = nullptr;
property.controller = nullptr;
property.mController = nullptr;
property.type = GetParam().mShaderType;
node.props.push_back(Nif::RecordPtrT<Nif::Property>(&property));
node.mProperties.push_back(Nif::RecordPtrT<Nif::Property>(&property));
Nif::NIFFile file("test.nif");
file.mRoots.push_back(&node);
auto result = Loader::load(file, &mImageManager);
Expand Down
26 changes: 17 additions & 9 deletions components/nif/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ namespace Nif
}
}

void Named::read(NIFStream* nif)
void NiObjectNET::read(NIFStream* nif)
{
name = nif->getString();
nif->read(mName);
if (nif->getVersion() < NIFStream::generateVersion(10, 0, 1, 0))
extra.read(nif);
mExtra.read(nif);
else
readRecordList(nif, extralist);
controller.read(nif);
readRecordList(nif, mExtraList);
mController.read(nif);
}

void Named::post(Reader& nif)
void NiObjectNET::post(Reader& nif)
{
extra.post(nif);
postRecordList(nif, extralist);
controller.post(nif);
mExtra.post(nif);
postRecordList(nif, mExtraList);
mController.post(nif);
}

ExtraList NiObjectNET::getExtraList() const
{
ExtraList list = mExtraList;
for (ExtraPtr extra = mExtra; !extra.empty(); extra = extra->mNext)
list.emplace_back(extra);
return list;
}
}
20 changes: 11 additions & 9 deletions components/nif/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Nif
int flags;
float frequency, phase;
float timeStart, timeStop;
NamedPtr target;
NiObjectNETPtr target;

void read(NIFStream* nif) override;
void post(Reader& nif) override;
Expand All @@ -49,18 +49,20 @@ namespace Nif
ExtrapolationMode extrapolationMode() const { return static_cast<ExtrapolationMode>(flags & Mask); }
};

/// Has name, extra-data and controller
struct Named : public Record
/// Abstract object that has a name, extra data and controllers
struct NiObjectNET : public Record
{
std::string name;
ExtraPtr extra;
ExtraList extralist;
ControllerPtr controller;
std::string mName;
ExtraPtr mExtra;
ExtraList mExtraList;
ControllerPtr mController;

void read(NIFStream* nif) override;
void post(Reader& nif) override;

// Collect extra records attached to the object
ExtraList getExtraList() const;
};
using NiSequenceStreamHelper = Named;

} // Namespace
}
#endif
2 changes: 1 addition & 1 deletion components/nif/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ namespace Nif
{
NiInterpController::read(nif);
size_t numTargets = nif->getUShort();
std::vector<NodePtr> targets;
std::vector<NiAVObjectPtr> targets;
targets.resize(numTargets);
for (size_t i = 0; i < targets.size(); i++)
targets[i].read(nif);
Expand Down
6 changes: 3 additions & 3 deletions components/nif/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace Nif

osg::Vec3f offsetRandom;

NodePtr emitter;
NiAVObjectPtr emitter;

int numParticles;
int activeCount;
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace Nif

struct NiLookAtController : public Controller
{
NodePtr target;
NiAVObjectPtr target;
unsigned short lookAtFlags{ 0 };

void read(NIFStream* nif) override;
Expand All @@ -237,7 +237,7 @@ namespace Nif

struct NiMultiTargetTransformController : public NiInterpController
{
NodeList mExtraTargets;
NiAVObjectList mExtraTargets;

void read(NIFStream* nif) override;
void post(Reader& nif) override;
Expand Down
8 changes: 2 additions & 6 deletions components/nif/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ namespace Nif

void NiSkinData::read(NIFStream* nif)
{
nif->read(mTransform.rotation);
nif->read(mTransform.pos);
nif->read(mTransform.scale);
nif->read(mTransform);

uint32_t numBones;
nif->read(numBones);
Expand All @@ -366,9 +364,7 @@ namespace Nif
mBones.resize(numBones);
for (BoneInfo& bi : mBones)
{
nif->read(bi.mTransform.rotation);
nif->read(bi.mTransform.pos);
nif->read(bi.mTransform.scale);
nif->read(bi.mTransform);
nif->read(bi.mBoundSphere);

uint16_t numVertices;
Expand Down
37 changes: 7 additions & 30 deletions components/nif/data.hpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
/*
OpenMW - The completely unofficial reimplementation of Morrowind
Copyright (C) 2008-2010 Nicolay Korslund
Email: < [email protected] >
WWW: https://openmw.org/
This file (data.h) is part of the OpenMW package.
OpenMW is distributed as free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
version 3 along with this program. If not, see
https://www.gnu.org/licenses/ .
*/

#ifndef OPENMW_COMPONENTS_NIF_DATA_HPP
#define OPENMW_COMPONENTS_NIF_DATA_HPP

#include "nifkey.hpp"
#include "niftypes.hpp" // Transformation
#include "niftypes.hpp" // NiTransform
#include "node.hpp"
#include "recordptr.hpp"
#include <components/nif/node.hpp>

namespace Nif
{
Expand Down Expand Up @@ -252,8 +229,8 @@ namespace Nif
{
NiSkinDataPtr mData;
NiSkinPartitionPtr mPartitions;
NodePtr mRoot;
NodeList mBones;
NiAVObjectPtr mRoot;
NiAVObjectList mBones;

void read(NIFStream* nif) override;
void post(Reader& nif) override;
Expand All @@ -278,12 +255,12 @@ namespace Nif

struct BoneInfo
{
Transformation mTransform;
NiTransform mTransform;
osg::BoundingSpheref mBoundSphere;
std::vector<VertWeight> mWeights;
};

Transformation mTransform;
NiTransform mTransform;
std::vector<BoneInfo> mBones;
NiSkinPartitionPtr mPartitions;

Expand Down Expand Up @@ -413,5 +390,5 @@ namespace Nif
void read(NIFStream* nif) override;
};

} // Namespace
}
#endif
2 changes: 1 addition & 1 deletion components/nif/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Nif

void NiDynamicEffect::read(NIFStream* nif)
{
Node::read(nif);
NiAVObject::read(nif);

if (nif->getVersion() > NIFFile::VER_MW && nif->getVersion() < nif->generateVersion(10, 1, 0, 0))
return;
Expand Down
2 changes: 1 addition & 1 deletion components/nif/effect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Nif
{

// Abstract
struct NiDynamicEffect : public Node
struct NiDynamicEffect : public NiAVObject
{
bool mSwitchState{ true };
void read(NIFStream* nif) override;
Expand Down
Loading

0 comments on commit 42b7734

Please sign in to comment.