11 const std::byte* vtxData, std::size_t vtxSize,
12 const std::byte* vvdData, std::size_t vvdSize) {
13 if (this->opened || !mdlData || !vtxData || !vvdData || !mdlSize || !vtxSize || !vvdSize) {
16 if ((!this->
mdl.
open(mdlData, mdlSize) ||
17 !this->vtx.open(vtxData, vtxSize, this->mdl)) ||
18 !this->vvd.open(vvdData, vvdSize, this->mdl)) {
26 const unsigned char* vtxData, std::size_t vtxSize,
27 const unsigned char* vvdData, std::size_t vvdSize) {
28 return this->
open(
reinterpret_cast<const std::byte*
>(mdlData), mdlSize,
29 reinterpret_cast<const std::byte*
>(vtxData), vtxSize,
30 reinterpret_cast<const std::byte*
>(vvdData), vvdSize);
34 const std::vector<std::byte>& vtxData,
35 const std::vector<std::byte>& vvdData) {
36 return this->
open(mdlData.data(), mdlData.size(),
37 vtxData.data(), vtxData.size(),
38 vvdData.data(), vvdData.size());
42 const std::vector<unsigned char>& vtxData,
43 const std::vector<unsigned char>& vvdData) {
44 return this->
open(mdlData.data(), mdlData.size(),
45 vtxData.data(), vtxData.size(),
46 vvdData.data(), vvdData.size());
49StudioModel::operator bool()
const {
57 static constexpr auto convertVertex = [](
const VVD::Vertex& vertex) {
61 std::transform(this->
vvd.
vertices.begin(), this->vvd.vertices.end(), std::back_inserter(model.
vertices), convertVertex);
63 for (
const auto& [LOD, sourceVertexID, vertexCount] : this->
vvd.
fixups) {
64 if (LOD < currentLOD) {
67 std::span fixupVertices{this->
vvd.
vertices.begin() + sourceVertexID,
static_cast<std::span<const VVD::Vertex>::size_type
>(vertexCount)};
68 std::transform(fixupVertices.begin(), fixupVertices.end(), std::back_inserter(model.
vertices), convertVertex);
72 for (
int bodyPartIndex = 0; bodyPartIndex < this->
mdl.
bodyParts.size(); bodyPartIndex++) {
73 auto& mdlBodyPart = this->
mdl.
bodyParts.at(bodyPartIndex);
74 auto& vtxBodyPart = this->
vtx.
bodyParts.at(bodyPartIndex);
76 for (
int modelIndex = 0; modelIndex < mdlBodyPart.models.size(); modelIndex++) {
77 auto& mdlModel = mdlBodyPart.models.at(modelIndex);
78 auto& vtxModel = vtxBodyPart.models.at(modelIndex);
80 if (mdlModel.verticesCount == 0) {
84 for (
int meshIndex = 0; meshIndex < mdlModel.meshes.size(); meshIndex++) {
85 auto& mdlMesh = mdlModel.meshes.at(meshIndex);
86 auto& vtxMesh = vtxModel.modelLODs.at(currentLOD).meshes.at(meshIndex);
88 std::vector<uint16_t> indices;
89 for (
const auto& stripGroup : vtxMesh.stripGroups) {
90 for (
const auto& strip : stripGroup.strips) {
91 const auto addIndex = [&indices, mdlMesh, mdlModel, stripGroup](
int index) {
92 indices.push_back(stripGroup.vertices.at(index).meshVertexID + mdlMesh.verticesOffset + mdlModel.verticesOffset);
97 for (
int i = 0; i < strip.indices.size(); i += 3) {
98 addIndex(strip.indices[ i ]);
99 addIndex(strip.indices[i+2]);
100 addIndex(strip.indices[i+1]);
103 for (
auto i = strip.indices.size() - 1; i >= 2; i -= 3) {
104 addIndex(strip.indices[ i ]);
105 addIndex(strip.indices[i-2]);
106 addIndex(strip.indices[i-1]);
112 model.
meshes.push_back({std::move(indices), mdlMesh.material});
sourcepp::math::Vec3f position
A more accessible version of StudioModel's vertex data, so it can be rendered or converted more easil...
std::vector< Vertex > vertices
std::vector< Mesh > meshes
bool open(const std::byte *data, std::size_t size)
std::vector< BodyPart > bodyParts
bool open(const std::byte *mdlData, std::size_t mdlSize, const std::byte *vtxData, std::size_t vtxSize, const std::byte *vvdData, std::size_t vvdSize)
BakedModel processModelData(int currentLOD=ROOT_LOD) const
std::vector< BodyPart > bodyParts
std::vector< Fixup > fixups
std::vector< Vertex > vertices