Skip to content

Commit

Permalink
add mod xD3 x64
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatorCZ committed Nov 6, 2023
1 parent 02da0ed commit 2989091
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
50 changes: 47 additions & 3 deletions src/mtf_mod/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,12 +1001,27 @@ std::map<uint32, MODVertices> formats{
V{F::UNORM, D::R8G8B8A8, U::BoneWeights},
TexCoordPhone),
},
{
0x667B1019, // P3s_unk1s_N4c_VC4c_U2h_T4c
BuildVertices(VertexQPosition,
V{F::UINT, D::R16, U::Undefined},
VertexNormal,
VertexColor,
TexCoord,
VertexTangent),
},
};

// clang-format on

static const std::set<uint32> edgeModels{
0xdb7da014,
// P3s_unk1s_B4c_W4c_N4c
0x0CB68015,
// P3s_B1s_N4c
0xB0983013,
// P3s_unk1s_B8c_W8c_N4c
0xA320C016,
};

static const auto makeV2 = [](auto &self, revil::MODImpl &main, bool swap,
Expand All @@ -1016,7 +1031,22 @@ static const auto makeV2 = [](auto &self, revil::MODImpl &main, bool swap,
retval.lodIndex =
convertLod(reinterpret_cast<es::Flags<uint8> &>(visibleLOD));
retval.materialIndex = self.data0.template Get<MODMeshXC5::MaterialIndex>();
retval.indexType = uni::Primitive::IndexType_e::Strip;
const MODMeshXC5::PrimitiveType_e primitiveType = MODMeshXC5::PrimitiveType_e(
self.data1.template Get<MODMeshXC5::PrimitiveType>());

switch (primitiveType) {
case MODMeshXC5::PrimitiveType_e::Triangles:
retval.indexType = uni::Primitive::IndexType_e::Triangle;
break;

case MODMeshXC5::PrimitiveType_e::Strips:
retval.indexType = uni::Primitive::IndexType_e::Strip;
break;

default:
retval.indexType = uni::Primitive::IndexType_e::None;
break;
}
retval.indexIndex = main.indices.Size();
retval.vertexIndex = main.vertices.Size();
retval.name = std::to_string(self.meshIndex) + ":" +
Expand All @@ -1041,8 +1071,11 @@ static const auto makeV2 = [](auto &self, revil::MODImpl &main, bool swap,
main.vertices.storage.emplace_back(std::move(tmpl));
} else {
main.vertices.storage.emplace_back();
// throw std::runtime_error("Unregistered vertex format: " +
// std::to_string(vertexFormat));

/*if (!edgeModels.contains(self.vertexFormat)) {
throw std::runtime_error("Unregistered vertex format: " +
std::to_string(self.vertexFormat));
}*/
}

uint16 *indexBuffer = reinterpret_cast<uint16 *>(
Expand Down Expand Up @@ -1150,6 +1183,17 @@ MODPrimitiveProxy MODMeshXD3PS4::ReflectLE(revil::MODImpl &main_) {
});
}

MODPrimitiveProxy MODMeshXD3::ReflectLE(revil::MODImpl &main_) {
auto &main = static_cast<MODInner<MODTraitsXD2> &>(main_);
return makeV2(*this, main, false, [&](MODVertexDescriptor &d) {
if (d.usage == uni::PrimitiveDescriptor::Usage_e::BoneIndices &&
skinBoneBegin) {
d.unpackType = uni::PrimitiveDescriptor::UnpackDataType_e::Add;
d.unpackData.min = Vector4A16(skinBoneBegin);
}
});
}

MODPrimitiveProxy MODMeshXC5::ReflectLE(revil::MODImpl &main_) {
auto &main = static_cast<MODInner<MODTraitsXC5> &>(main_);
return makeV2(*this, main, false, [&](MODVertexDescriptor &) {});
Expand Down
11 changes: 9 additions & 2 deletions src/mtf_mod/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ struct MODMeshXC5 {
using Unk00 = BitMemberDecl<3, 5>;
using Unk01 = BitMemberDecl<4, 8>;
using VertexBufferStride = BitMemberDecl<5, 8>;
using PrimitiveType = BitMemberDecl<6, 8>;
using PrimitiveType = BitMemberDecl<6, 5>;
using Unk02 = BitMemberDecl<7, 3>;
using BitField01 = BitFieldType<uint32, Visible, Flag0, Flag1, Unk00, Unk01,
VertexBufferStride, PrimitiveType>;
VertexBufferStride, PrimitiveType, Unk02>;

enum class PrimitiveType_e : uint8 {
Points,
Expand Down Expand Up @@ -147,6 +148,12 @@ struct MODMeshXD2 {
MODPrimitiveProxy ReflectBE(revil::MODImpl &);
};

struct MODMeshXD3 : MODMeshXD2 {
MODPrimitiveProxy ReflectLE(revil::MODImpl &);
MODPrimitiveProxy ReflectBE(revil::MODImpl &) { return {}; }
void NoSwap();
};

struct MODMeshXD3PS4 : MODMeshXD2 {
MODPrimitiveProxy ReflectLE(revil::MODImpl &);
MODPrimitiveProxy ReflectBE(revil::MODImpl &) { return {}; }
Expand Down
6 changes: 4 additions & 2 deletions src/mtf_mod/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,10 @@ template <class Traits> MODImpl::ptr LoadMODXD2x32(BinReaderRef_e rd) {
return std::make_unique<decltype(main)>(std::move(main));
}

template<class Traits>
MODImpl::ptr LoadMODXD3x64(BinReaderRef_e rdn) {
MODHeaderXD3X64 header;
MODInner<MODTraitsXD3PS4> main;
MODInner<Traits> main;
BinReaderRef rd(rdn);
rd.Push();
rd.Read(header);
Expand Down Expand Up @@ -959,7 +960,8 @@ static const std::map<MODMaker, MODImpl::ptr (*)(BinReaderRef_e)> modLoaders{
{{MODVersion::XC5, false}, LoadMODXC5},
{{MODVersion::XD2, true}, LoadMODXD2x32<MODTraitsXD2>},
{{MODVersion::XD3, true}, LoadMODXD2x32<MODTraitsXD2>},
{{MODVersion::XD3, false}, LoadMODXD3x64},
{{MODVersion::XD3, false, false, Platform::PS4}, LoadMODXD3x64<MODTraitsXD3PS4>},
{{MODVersion::XD3, false}, LoadMODXD3x64<MODTraitsXD3x64>},
{{MODVersion::X05, false}, LoadMODX06},
{{MODVersion::X06, false}, LoadMODX06},
};
Expand Down
4 changes: 4 additions & 0 deletions src/mtf_mod/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ struct MODTraitsXD3PS4 : MODTraitsXD2 {
using mesh = MODMeshXD3PS4;
};

struct MODTraitsXD3x64 : MODTraitsXD2 {
using mesh = MODMeshXD3;
};

struct MODTraitsX06 {
static constexpr size_t numSkinRemaps = 32;
static constexpr size_t numRemaps = 0x100;
Expand Down
3 changes: 1 addition & 2 deletions toolset/mod_to_gltf/mod_to_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ void MODGLTF::ProcessModel(const uni::Model &model) {
prim.indices = indicesIndices.at(p->IndexArrayIndex());
prim.attributes = attrs;
prim.material = p->MaterialIndex();
prim.mode = gltf::Primitive::Mode::TriangleStrip;
[&] {
prim.mode = [&] {
switch (p->IndexType()) {
case uni::Primitive::IndexType_e::Triangle:
return gltf::Primitive::Mode::Triangles;
Expand Down

0 comments on commit 2989091

Please sign in to comment.