Skip to content

Commit

Permalink
feat: parse skins in studiomodelpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Trico-Everfire authored and craftablescience committed Apr 10, 2024
1 parent 19e3b5b commit a8dc319
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/studiomodelpp/structs/MDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ struct MDL {
//int skinReferenceCount;
//int skinReferenceFamilyCount;
//int skinReferenceIndex;
// Each vector is an individual skin, which holds indices into the materials vector
std::vector<std::vector<short>> skins;

//int bodyPartCount;
//int bodyPartOffset;
Expand Down
15 changes: 13 additions & 2 deletions src/studiomodelpp/structs/MDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ bool MDL::open(const std::byte* data, std::size_t size) {
int materialDirCount = stream.read<int>();
int materialDirOffset = stream.read<int>();

// todo: skins
stream.skip<int>(3);
int skinReferenceCount = stream.read<int>();
int skinReferenceFamilyCount = stream.read<int>();
int skinReferenceOffset = stream.read<int>();

int bodyPartCount = stream.read<int>();
int bodyPartOffset = stream.read<int>();
Expand Down Expand Up @@ -127,6 +128,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
// note: we don't know what model versions use absolute vs. relative offsets here
// and this is unimportant, so skip parsing the bbox name here
//readStringAtOffset(stream, hitbox.name, std::ios::cur, sizeof(int) * 3 + sizeof(Vector3) * 2);
stream.skip<int>();
hitbox.name = "";

// _unused0
Expand Down Expand Up @@ -167,6 +169,15 @@ bool MDL::open(const std::byte* data, std::size_t size) {
readStringAtOffset(stream, materialDir, std::ios::beg, 0);
}

stream.seek(skinReferenceOffset);
for (int i = 0; i < skinReferenceFamilyCount; i++) {
std::vector<short> skinFamily;
for (int j = 0; j < skinReferenceCount; j++) {
skinFamily.push_back(stream.read<short>());
}
this->skins.push_back(std::move(skinFamily));
}

for (int i = 0; i < bodyPartCount; i++) {
auto bodyPartPos = bodyPartOffset + i * (sizeof(int) * 4);
stream.seek(bodyPartPos);
Expand Down

0 comments on commit a8dc319

Please sign in to comment.