Skip to content

Commit

Permalink
Merge branch 'anothersettlementneedsyourhelp' into 'master'
Browse files Browse the repository at this point in the history
Read all official Fallout 4 NIF files

See merge request OpenMW/openmw!3506
  • Loading branch information
Assumeru committed Oct 22, 2023
2 parents 418c3d2 + 8ce9f7b commit 536a167
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 5 deletions.
46 changes: 46 additions & 0 deletions components/nif/extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,50 @@ namespace Nif
nif->getSizedStrings(mPointNames, nif->get<uint32_t>());
}

void BSPackedGeomDataCombined::read(NIFStream* nif)
{
nif->read(mGrayscaleToPaletteScale);
nif->read(mTransform);
nif->read(mBoundingSphere);
}

void BSPackedGeomObject::read(NIFStream* nif)
{
nif->read(mFileHash);
nif->read(mDataOffset);
}

void BSPackedSharedGeomData::read(NIFStream* nif)
{
nif->read(mNumVertices);
nif->read(mLODLevels);
nif->read(mLOD0TriCount);
nif->read(mLOD0TriOffset);
nif->read(mLOD1TriCount);
nif->read(mLOD1TriOffset);
nif->read(mLOD2TriCount);
nif->read(mLOD2TriOffset);
mCombined.resize(nif->get<uint32_t>());
for (BSPackedGeomDataCombined& data : mCombined)
data.read(nif);
mVertexDesc.read(nif);
}

void BSPackedCombinedSharedGeomDataExtra::read(NIFStream* nif)
{
NiExtraData::read(nif);

mVertexDesc.read(nif);
nif->read(mNumVertices);
nif->read(mNumTriangles);
nif->read(mFlags1);
nif->read(mFlags2);
mObjects.resize(nif->get<uint32_t>());
for (BSPackedGeomObject& object : mObjects)
object.read(nif);
mObjectData.resize(mObjects.size());
for (BSPackedSharedGeomData& objectData : mObjectData)
objectData.read(nif);
}

}
47 changes: 47 additions & 0 deletions components/nif/extra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OPENMW_COMPONENTS_NIF_EXTRA_HPP

#include "base.hpp"
#include "node.hpp"

namespace Nif
{
Expand Down Expand Up @@ -199,5 +200,51 @@ namespace Nif
};
};

struct BSPackedGeomDataCombined
{
float mGrayscaleToPaletteScale;
NiTransform mTransform;
osg::BoundingSpheref mBoundingSphere;

void read(NIFStream* nif);
};

struct BSPackedGeomObject
{
uint32_t mFileHash;
uint32_t mDataOffset;

void read(NIFStream* nif);
};

struct BSPackedSharedGeomData
{
uint32_t mNumVertices;
uint32_t mLODLevels;
uint32_t mLOD0TriCount;
uint32_t mLOD0TriOffset;
uint32_t mLOD1TriCount;
uint32_t mLOD1TriOffset;
uint32_t mLOD2TriCount;
uint32_t mLOD2TriOffset;
std::vector<BSPackedGeomDataCombined> mCombined;
BSVertexDesc mVertexDesc;

void read(NIFStream* nif);
};

struct BSPackedCombinedSharedGeomDataExtra : NiExtraData
{
BSVertexDesc mVertexDesc;
uint32_t mNumVertices;
uint32_t mNumTriangles;
uint32_t mFlags1;
uint32_t mFlags2;
std::vector<BSPackedGeomObject> mObjects;
std::vector<BSPackedSharedGeomData> mObjectData;

void read(NIFStream* nif) override;
};

}
#endif
5 changes: 5 additions & 0 deletions components/nif/niffile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ namespace Nif
&construct<BSEffectShaderPropertyColorController, RC_BSLightingShaderPropertyColorController> },
{ "BSLightingShaderPropertyFloatController",
&construct<BSEffectShaderPropertyFloatController, RC_BSLightingShaderPropertyFloatController> },
{ "BSLightingShaderPropertyUShortController",
&construct<BSEffectShaderPropertyFloatController, RC_BSLightingShaderPropertyUShortController> },
{ "bhkBlendController", &construct<bhkBlendController, RC_bhkBlendController> },
{ "NiBSBoneLODController", &construct<NiBoneLODController, RC_NiBoneLODController> },
{ "NiLightRadiusController", &construct<NiFloatInterpController, RC_NiLightRadiusController> },
Expand Down Expand Up @@ -254,6 +256,8 @@ namespace Nif
{ "BSDistantObjectLargeRefExtraData",
&construct<BSDistantObjectLargeRefExtraData, RC_BSDistantObjectLargeRefExtraData> },
{ "BSEyeCenterExtraData", &construct<BSEyeCenterExtraData, RC_BSEyeCenterExtraData> },
{ "BSPackedCombinedSharedGeomDataExtra",
&construct<BSPackedCombinedSharedGeomDataExtra, RC_BSPackedCombinedSharedGeomDataExtra> },
{ "BSPositionData", &construct<BSPositionData, RC_BSPositionData> },
{ "BSWArray", &construct<BSWArray, RC_BSWArray> },
{ "BSXFlags", &construct<NiIntegerExtraData, RC_BSXFlags> },
Expand All @@ -280,6 +284,7 @@ namespace Nif
{ "BSLODTriShape", &construct<BSLODTriShape, RC_BSLODTriShape> },
{ "BSMeshLODTriShape", &construct<BSMeshLODTriShape, RC_BSMeshLODTriShape> },
{ "BSSegmentedTriShape", &construct<BSSegmentedTriShape, RC_BSSegmentedTriShape> },
{ "BSSubIndexTriShape", &construct<BSSubIndexTriShape, RC_BSSubIndexTriShape> },

// PARTICLES

Expand Down
75 changes: 70 additions & 5 deletions components/nif/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,20 @@ namespace Nif
}
}

void BSSegmentedTriShape::SegmentData::read(NIFStream* nif)
{
nif->read(mFlags);
nif->read(mStartIndex);
nif->read(mNumTriangles);
}

void BSSegmentedTriShape::read(NIFStream* nif)
{
NiTriShape::read(nif);

mSegments.resize(nif->get<uint32_t>());
for (SegmentData& segment : mSegments)
{
nif->read(segment.mFlags);
nif->read(segment.mStartIndex);
nif->read(segment.mNumTriangles);
}
segment.read(nif);
}

void BSLODTriShape::read(NIFStream* nif)
Expand Down Expand Up @@ -447,6 +450,68 @@ namespace Nif
nif->readArray(mLOD);
}

void BSSubIndexTriShape::SubSegment::read(NIFStream* nif)
{
nif->read(mStartIndex);
nif->read(mNumPrimitives);
nif->read(mArrayIndex);
nif->skip(4); // Unknown
}

void BSSubIndexTriShape::Segment::read(NIFStream* nif)
{
nif->read(mStartIndex);
nif->read(mNumPrimitives);
nif->read(mParentArrayIndex);
mSubSegments.resize(nif->get<uint32_t>());
for (SubSegment& subsegment : mSubSegments)
subsegment.read(nif);
}

void BSSubIndexTriShape::SubSegmentDataRecord::read(NIFStream* nif)
{
nif->read(mUserSlotID);
nif->read(mMaterial);
nif->readVector(mExtraData, nif->get<uint32_t>());
}

void BSSubIndexTriShape::SubSegmentData::read(NIFStream* nif)
{
uint32_t numArrayIndices;
nif->read(numArrayIndices);
mDataRecords.resize(nif->get<uint32_t>());
nif->readVector(mArrayIndices, numArrayIndices);
for (SubSegmentDataRecord& dataRecord : mDataRecords)
dataRecord.read(nif);
mSSFFile = nif->getSizedString(nif->get<uint16_t>());
}

void BSSubIndexTriShape::Segmentation::read(NIFStream* nif)
{
nif->read(mNumPrimitives);
mSegments.resize(nif->get<uint32_t>());
nif->read(mNumTotalSegments);
for (Segment& segment : mSegments)
segment.read(nif);

if (mSegments.size() < mNumTotalSegments)
mSubSegmentData.read(nif);
}

void BSSubIndexTriShape::read(NIFStream* nif)
{
BSTriShape::read(nif);

if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE)
{
mSegments.resize(nif->get<uint32_t>());
for (BSSegmentedTriShape::SegmentData& segment : mSegments)
segment.read(nif);
}
else if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_FO4 && mDataSize > 0)
mSegmentation.read(nif);
}

void BSVertexDesc::read(NIFStream* nif)
{
uint64_t data;
Expand Down
57 changes: 57 additions & 0 deletions components/nif/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ namespace Nif
uint8_t mFlags;
uint32_t mStartIndex;
uint32_t mNumTriangles;

void read(NIFStream* nif);
};

std::vector<SegmentData> mSegments;
Expand Down Expand Up @@ -396,6 +398,61 @@ namespace Nif
void read(NIFStream* nif) override;
};

struct BSSubIndexTriShape : BSTriShape
{
struct SubSegment
{
uint32_t mStartIndex;
uint32_t mNumPrimitives;
uint32_t mArrayIndex;

void read(NIFStream* nif);
};

struct Segment
{
uint32_t mStartIndex;
uint32_t mNumPrimitives;
uint32_t mParentArrayIndex;
std::vector<SubSegment> mSubSegments;

void read(NIFStream* nif);
};

struct SubSegmentDataRecord
{
uint32_t mUserSlotID;
uint32_t mMaterial;
std::vector<float> mExtraData;

void read(NIFStream* nif);
};

struct SubSegmentData
{
std::vector<uint32_t> mArrayIndices;
std::vector<SubSegmentDataRecord> mDataRecords;
std::string mSSFFile;

void read(NIFStream* nif);
};

struct Segmentation
{
uint32_t mNumPrimitives;
uint32_t mNumTotalSegments;
std::vector<Segment> mSegments;
SubSegmentData mSubSegmentData;

void read(NIFStream* nif);
};

std::vector<BSSegmentedTriShape::SegmentData> mSegments; // SSE
Segmentation mSegmentation; // FO4

void read(NIFStream* nif) override;
};

struct BSValueNode : NiNode
{
enum Flags
Expand Down
3 changes: 3 additions & 0 deletions components/nif/record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace Nif
RC_BSLightingShaderProperty,
RC_BSLightingShaderPropertyColorController,
RC_BSLightingShaderPropertyFloatController,
RC_BSLightingShaderPropertyUShortController,
RC_BSLODTriShape,
RC_BSMaterialEmittanceMultController,
RC_BSMeshLODTriShape,
Expand All @@ -107,6 +108,7 @@ namespace Nif
RC_BSMultiBoundSphere,
RC_BSNiAlphaPropertyTestRefController,
RC_BSPackedAdditionalGeometryData,
RC_BSPackedCombinedSharedGeomDataExtra,
RC_BSParentVelocityModifier,
RC_BSPositionData,
RC_BSProceduralLightningController,
Expand All @@ -132,6 +134,7 @@ namespace Nif
RC_BSSkinBoneData,
RC_BSSkinInstance,
RC_BSSkyShaderProperty,
RC_BSSubIndexTriShape,
RC_BSTriShape,
RC_BSWArray,
RC_BSWaterShaderProperty,
Expand Down
1 change: 1 addition & 0 deletions components/nifosg/nifloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace
case Nif::RC_BSTriShape:
case Nif::RC_BSDynamicTriShape:
case Nif::RC_BSMeshLODTriShape:
case Nif::RC_BSSubIndexTriShape:
return true;
}
return false;
Expand Down

0 comments on commit 536a167

Please sign in to comment.