Skip to content

Commit

Permalink
Don't create BSDismemberSkinInstance for games that don't have it
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Sep 6, 2024
1 parent 3a2ff3d commit 34e4170
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/NifFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2959,7 +2959,7 @@ void NifFile::SetShapePartitions(NiShape* shape,

// Set BSDismemberSkinInstance partition list
auto bsdSkinInst = hdr.GetBlock<BSDismemberSkinInstance>(shape->SkinInstanceRef());
if (!bsdSkinInst && convertSkinInstance) {
if (!bsdSkinInst && convertSkinInstance && hdr.GetVersion().File() == NiFileVersion::V20_2_0_7) {
auto newBsdSkinInst = std::make_unique<BSDismemberSkinInstance>();
bsdSkinInst = newBsdSkinInst.get();

Expand Down Expand Up @@ -4454,35 +4454,29 @@ void NifFile::UpdatePartitionFlags(NiShape* shape) {
}

void NifFile::CreateSkinning(NiShape* shape) {
if (shape->HasType<NiTriShape>()) {
if (shape->HasType<NiTriShape>() || shape->HasType<NiTriStrips>()) {
if (shape->SkinInstanceRef()->IsEmpty()) {
int skinDataID = hdr.AddBlock(std::make_unique<NiSkinData>());
int partID = hdr.AddBlock(std::make_unique<NiSkinPartition>());

auto [nifDismemberInstS, nifDismemberInst] = make_unique<BSDismemberSkinInstance>();
int dismemberID = hdr.AddBlock(std::move(nifDismemberInstS));
NiSkinInstance* skinInst;
int skinInstID;

nifDismemberInst->dataRef.index = skinDataID;
nifDismemberInst->skinPartitionRef.index = partID;
nifDismemberInst->targetRef.index = GetBlockID(GetRootNode());
shape->SkinInstanceRef()->index = dismemberID;
shape->SetSkinned(true);

SetDefaultPartition(shape);
}
}
else if (shape->HasType<NiTriStrips>()) {
if (shape->SkinInstanceRef()->IsEmpty()) {
int skinDataID = hdr.AddBlock(std::make_unique<NiSkinData>());
int partID = hdr.AddBlock(std::make_unique<NiSkinPartition>());

auto [nifDismemberInstS, nifDismemberInst] = make_unique<BSDismemberSkinInstance>();
int skinID = hdr.AddBlock(std::move(nifDismemberInstS));
if (hdr.GetVersion().File() == NiFileVersion::V20_2_0_7) {
auto [nifDismemberInstS, nifDismemberInst] = make_unique<BSDismemberSkinInstance>();
skinInstID = hdr.AddBlock(std::move(nifDismemberInstS));
skinInst = nifDismemberInst;
}
else {
auto [nifSkinInstS, nifSkinInst] = make_unique<NiSkinInstance>();
skinInstID = hdr.AddBlock(std::move(nifSkinInstS));
skinInst = nifSkinInst;
}

nifDismemberInst->dataRef.index = skinDataID;
nifDismemberInst->skinPartitionRef.index = partID;
nifDismemberInst->targetRef.index = GetBlockID(GetRootNode());
shape->SkinInstanceRef()->index = skinID;
skinInst->dataRef.index = skinDataID;
skinInst->skinPartitionRef.index = partID;
skinInst->targetRef.index = GetBlockID(GetRootNode());
shape->SkinInstanceRef()->index = skinInstID;
shape->SetSkinned(true);

SetDefaultPartition(shape);
Expand Down

0 comments on commit 34e4170

Please sign in to comment.