mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-19 17:41:33 +00:00
Modernize skin instance records
This commit is contained in:
parent
30f4cd972d
commit
5b07a78f2c
4 changed files with 65 additions and 50 deletions
|
@ -53,8 +53,8 @@ namespace Nif::Testing
|
||||||
|
|
||||||
inline void init(NiSkinInstance& value)
|
inline void init(NiSkinInstance& value)
|
||||||
{
|
{
|
||||||
value.data = NiSkinDataPtr(nullptr);
|
value.mData = NiSkinDataPtr(nullptr);
|
||||||
value.root = NodePtr(nullptr);
|
value.mRoot = NodePtr(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void init(Controller& value)
|
inline void init(Controller& value)
|
||||||
|
|
|
@ -7,43 +7,6 @@
|
||||||
|
|
||||||
namespace Nif
|
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)
|
void NiGeometryData::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 114))
|
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 114))
|
||||||
|
@ -121,6 +84,7 @@ namespace Nif
|
||||||
void NiTriBasedGeomData::read(NIFStream* nif)
|
void NiTriBasedGeomData::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
NiGeometryData::read(nif);
|
NiGeometryData::read(nif);
|
||||||
|
|
||||||
mNumTriangles = nif->getUShort();
|
mNumTriangles = nif->getUShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +138,7 @@ namespace Nif
|
||||||
void NiLinesData::read(NIFStream* nif)
|
void NiLinesData::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
NiGeometryData::read(nif);
|
NiGeometryData::read(nif);
|
||||||
|
|
||||||
size_t num = vertices.size();
|
size_t num = vertices.size();
|
||||||
std::vector<uint8_t> flags;
|
std::vector<uint8_t> flags;
|
||||||
nif->readVector(flags, num);
|
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)
|
void NiSkinData::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
trafo.rotation = nif->getMatrix3();
|
trafo.rotation = nif->getMatrix3();
|
||||||
|
|
|
@ -172,10 +172,10 @@ namespace Nif
|
||||||
|
|
||||||
struct NiSkinInstance : public Record
|
struct NiSkinInstance : public Record
|
||||||
{
|
{
|
||||||
NiSkinDataPtr data;
|
NiSkinDataPtr mData;
|
||||||
NiSkinPartitionPtr partitions;
|
NiSkinPartitionPtr mPartitions;
|
||||||
NodePtr root;
|
NodePtr mRoot;
|
||||||
NodeList bones;
|
NodeList mBones;
|
||||||
|
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
void post(Reader& nif) override;
|
void post(Reader& nif) override;
|
||||||
|
@ -183,6 +183,14 @@ namespace Nif
|
||||||
|
|
||||||
struct BSDismemberSkinInstance : public NiSkinInstance
|
struct BSDismemberSkinInstance : public NiSkinInstance
|
||||||
{
|
{
|
||||||
|
struct BodyPart
|
||||||
|
{
|
||||||
|
uint16_t mFlags;
|
||||||
|
uint16_t mType;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<BodyPart> mParts;
|
||||||
|
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1391,14 +1391,14 @@ namespace NifOsg
|
||||||
const Nif::NiSkinInstance* skin = niGeometry->skin.getPtr();
|
const Nif::NiSkinInstance* skin = niGeometry->skin.getPtr();
|
||||||
const Nif::NiSkinData* data = nullptr;
|
const Nif::NiSkinData* data = nullptr;
|
||||||
const Nif::NiSkinPartition* partitions = 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())
|
if (!data->partitions.empty())
|
||||||
partitions = data->partitions.getPtr();
|
partitions = data->partitions.getPtr();
|
||||||
}
|
}
|
||||||
if (!partitions && !skin->partitions.empty())
|
if (!partitions && !skin->mPartitions.empty())
|
||||||
partitions = skin->partitions.getPtr();
|
partitions = skin->mPartitions.getPtr();
|
||||||
|
|
||||||
hasPartitions = partitions != nullptr;
|
hasPartitions = partitions != nullptr;
|
||||||
if (hasPartitions)
|
if (hasPartitions)
|
||||||
|
@ -1549,9 +1549,9 @@ namespace NifOsg
|
||||||
osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map(new SceneUtil::RigGeometry::InfluenceMap);
|
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::NiSkinInstance* skin = static_cast<const Nif::NiGeometry*>(nifNode)->skin.getPtr();
|
||||||
const Nif::NiSkinData* data = skin->data.getPtr();
|
const Nif::NiSkinData* data = skin->mData.getPtr();
|
||||||
const Nif::NodeList& bones = skin->bones;
|
const Nif::NodeList& bones = skin->mBones;
|
||||||
for (std::size_t i = 0, n = bones.size(); i < n; ++i)
|
for (std::size_t i = 0; i < bones.size(); ++i)
|
||||||
{
|
{
|
||||||
std::string boneName = Misc::StringUtils::lowerCase(bones[i].getPtr()->name);
|
std::string boneName = Misc::StringUtils::lowerCase(bones[i].getPtr()->name);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue