Modernize skin instance records

macos_ci_fix
Alexei Kotov 1 year ago
parent 30f4cd972d
commit 5b07a78f2c

@ -53,8 +53,8 @@ namespace Nif::Testing
inline void init(NiSkinInstance& value)
{
value.data = NiSkinDataPtr(nullptr);
value.root = NodePtr(nullptr);
value.mData = NiSkinDataPtr(nullptr);
value.mRoot = NodePtr(nullptr);
}
inline void init(Controller& value)

@ -7,43 +7,6 @@
namespace Nif
{
void NiSkinInstance::read(NIFStream* nif)
{
data.read(nif);
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 101))
partitions.read(nif);
root.read(nif);
readRecordList(nif, bones);
}
void NiSkinInstance::post(Reader& nif)
{
data.post(nif);
partitions.post(nif);
root.post(nif);
postRecordList(nif, bones);
if (data.empty() || root.empty())
throw Nif::Exception("NiSkinInstance missing root or data", nif.getFilename());
if (bones.size() != data->bones.size())
throw Nif::Exception("Mismatch in NiSkinData bone count", nif.getFilename());
for (auto& bone : bones)
{
if (bone.empty())
throw Nif::Exception("Oops: Missing bone! Don't know how to handle this.", nif.getFilename());
bone->setBone();
}
}
void BSDismemberSkinInstance::read(NIFStream* nif)
{
NiSkinInstance::read(nif);
unsigned int numPartitions = nif->getUInt();
nif->skip(4 * numPartitions); // Body part information
}
void NiGeometryData::read(NIFStream* nif)
{
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 114))
@ -121,6 +84,7 @@ namespace Nif
void NiTriBasedGeomData::read(NIFStream* nif)
{
NiGeometryData::read(nif);
mNumTriangles = nif->getUShort();
}
@ -174,6 +138,7 @@ namespace Nif
void NiLinesData::read(NIFStream* nif)
{
NiGeometryData::read(nif);
size_t num = vertices.size();
std::vector<uint8_t> flags;
nif->readVector(flags, num);
@ -326,6 +291,48 @@ namespace Nif
}
}
void NiSkinInstance::read(NIFStream* nif)
{
mData.read(nif);
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 101))
mPartitions.read(nif);
mRoot.read(nif);
readRecordList(nif, mBones);
}
void NiSkinInstance::post(Reader& nif)
{
mData.post(nif);
mPartitions.post(nif);
mRoot.post(nif);
postRecordList(nif, mBones);
if (mData.empty() || mRoot.empty())
throw Nif::Exception("NiSkinInstance missing root or data", nif.getFilename());
if (mBones.size() != mData->bones.size())
throw Nif::Exception("Mismatch in NiSkinData bone count", nif.getFilename());
for (auto& bone : mBones)
{
if (bone.empty())
throw Nif::Exception("Oops: Missing bone! Don't know how to handle this.", nif.getFilename());
bone->setBone();
}
}
void BSDismemberSkinInstance::read(NIFStream* nif)
{
NiSkinInstance::read(nif);
mParts.resize(nif->get<uint32_t>());
for (BodyPart& part : mParts)
{
nif->read(part.mFlags);
nif->read(part.mType);
}
}
void NiSkinData::read(NIFStream* nif)
{
trafo.rotation = nif->getMatrix3();

@ -172,10 +172,10 @@ namespace Nif
struct NiSkinInstance : public Record
{
NiSkinDataPtr data;
NiSkinPartitionPtr partitions;
NodePtr root;
NodeList bones;
NiSkinDataPtr mData;
NiSkinPartitionPtr mPartitions;
NodePtr mRoot;
NodeList mBones;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
@ -183,6 +183,14 @@ namespace Nif
struct BSDismemberSkinInstance : public NiSkinInstance
{
struct BodyPart
{
uint16_t mFlags;
uint16_t mType;
};
std::vector<BodyPart> mParts;
void read(NIFStream* nif) override;
};

@ -1391,14 +1391,14 @@ namespace NifOsg
const Nif::NiSkinInstance* skin = niGeometry->skin.getPtr();
const Nif::NiSkinData* data = nullptr;
const Nif::NiSkinPartition* partitions = nullptr;
if (!skin->data.empty())
if (!skin->mData.empty())
{
data = skin->data.getPtr();
data = skin->mData.getPtr();
if (!data->partitions.empty())
partitions = data->partitions.getPtr();
}
if (!partitions && !skin->partitions.empty())
partitions = skin->partitions.getPtr();
if (!partitions && !skin->mPartitions.empty())
partitions = skin->mPartitions.getPtr();
hasPartitions = partitions != nullptr;
if (hasPartitions)
@ -1549,9 +1549,9 @@ namespace NifOsg
osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map(new SceneUtil::RigGeometry::InfluenceMap);
const Nif::NiSkinInstance* skin = static_cast<const Nif::NiGeometry*>(nifNode)->skin.getPtr();
const Nif::NiSkinData* data = skin->data.getPtr();
const Nif::NodeList& bones = skin->bones;
for (std::size_t i = 0, n = bones.size(); i < n; ++i)
const Nif::NiSkinData* data = skin->mData.getPtr();
const Nif::NodeList& bones = skin->mBones;
for (std::size_t i = 0; i < bones.size(); ++i)
{
std::string boneName = Misc::StringUtils::lowerCase(bones[i].getPtr()->name);

Loading…
Cancel
Save