From b5d43c3d83b9277fdb66336fad2ac28ef0a57648 Mon Sep 17 00:00:00 2001 From: JaXt0r <120568393+JaXt0r@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:21:25 +0200 Subject: [PATCH] Get all mdm attachment keys via iterator. --- include/phoenix/cffi/ModelMesh.h | 4 +++- src/ModelMesh.cc | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/phoenix/cffi/ModelMesh.h b/include/phoenix/cffi/ModelMesh.h index f02b160..89fa3a0 100644 --- a/include/phoenix/cffi/ModelMesh.h +++ b/include/phoenix/cffi/ModelMesh.h @@ -24,7 +24,9 @@ PXC_API void pxMdmDestroy(PxModelMesh* mdm); PXC_API uint32_t pxMdmGetMeshCount(PxModelMesh const* mdm); PXC_API PxSoftSkinMesh const* pxMdmGetMesh(PxModelMesh const* mdm, uint32_t i); -PXC_API PxMultiResolutionMesh const* pxMdmGetAttachment(PxModelMesh const* mdm, char const* name); +PXC_API uint32_t pxMdmGetAttachmentCount(PxModelMesh const* mdm); +PXC_API char const* pxMdmGetAttachmentKey(PxModelMesh const* mdm, uint32_t index); +PXC_API PxMultiResolutionMesh const* pxMdmGetAttachmentValue(PxModelMesh const* mdm, char const* name); PXC_API uint32_t pxMdmGetChecksum(PxModelMesh const* mdm); PXC_API PxMultiResolutionMesh const* pxSsmGetMesh(PxSoftSkinMesh const* ssm); diff --git a/src/ModelMesh.cc b/src/ModelMesh.cc index 4a10db0..b99a472 100644 --- a/src/ModelMesh.cc +++ b/src/ModelMesh.cc @@ -40,11 +40,28 @@ PxSoftSkinMesh const* pxMdmGetMesh(PxModelMesh const* mdm, uint32_t i) { return &mdm->meshes[i]; } -PxMultiResolutionMesh const* pxMdmGetAttachment(PxModelMesh const* mdm, char const* name) { +uint32_t pxMdmGetAttachmentCount(PxModelMesh const* mdm) { + return mdm->attachments.size(); +} + +char const* pxMdmGetAttachmentKey(PxModelMesh const* mdm, uint32_t index) { auto& attachments = mdm->attachments; + uint32_t currentIndex = 0; + for (auto i = attachments.begin(); i != attachments.end(); i++) { + if (currentIndex++ == index) + return i->first.c_str(); + } + + return nullptr; +} + +PxMultiResolutionMesh const* pxMdmGetAttachmentValue(PxModelMesh const* mdm, char const* name) { + auto& attachments = mdm->attachments; auto rv = attachments.find(name); - if (rv == attachments.end()) return nullptr; + + if (rv == attachments.end()) + return nullptr; return &rv->second; }