Извлечение идентификаторов весовых соединений MD5 из данных Assimp после импорта
Для моего проекта игрового движка я создаю импортер моделей, который использует ассимп для импорта моделей, а затем пишущий экспортер возьмет эти данные сцены ассимп и преобразует информацию о модели во внутренний формат движков. (В моем случае внутренний формат более или менее представляет собой двоичную версию моделей MD5.)
Пока он у меня есть, поэтому все импортируется правильно, за исключением одной вещи, я не могу восстановить поле 'JointID' для каждого веса. Вот информация, которую я собираю со сцены Assimp:
typedef std::array<uint32_t, 3> Triangle;
struct Weight {
float m_Bias;
uint32_t m_JointID;
Vector3 m_Position;
};
struct VertexInfo { // Vertex information as stored in file.
Vector2 m_UVCoords;
struct {
uint32_t m_Start;
uint32_t m_Count;
} m_Weight;
};
struct Mesh {
std::vector<VertexInfo> m_VertexInfo;
std::vector<Weight> m_Weights;
std::vector<Triangle> m_Triangles;
std::string m_Material;
};
Weight:: m_JointID - это то, что я надеюсь извлечь из сцены assimp... следующий код для генерации весов, кажется, производит правильные отклонения веса для каждого веса... но он не может создать правильный JointID и пока исправлено Я не могу исправить расчет положения веса.
for (uint32_t vertexIndex = 0; vertexIndex < mesh.m_VertexInfo.size(); ++vertexIndex) {
Vector3 finalVertexPosition = ConvertAssimpVector3(assimpMesh->mVertices[vertexIndex]);
// Iterate vertex weights in REVERSE ORDER because we are working from finalVertexPosition back to weight positions.
uint32_t weightCount = mesh.m_VertexInfo[vertexIndex].m_Weight.m_Count;
for (uint32_t k = weightCount - 1; k >= 0 && k < weightCount; --k) {
// Determine what weight we're building, make sure it exists.
uint32_t weightIndex = mesh.m_VertexInfo[vertexIndex].m_Weight.m_Start + k;
if (weightIndex >= mesh.m_Weights.size()) mesh.m_Weights.resize(weightIndex + 1);
Weight& weight = mesh.m_Weights.at(weightIndex);
// Try and find the appropriate assimpWeight to import.
aiVertexWeight importWeight;
importWeight.mWeight = -999.99f;
for (const aiVertexWeight weight : pAIWeightList) {
if (weight.mVertexId == vertexIndex) {
importWeight = weight;
break;
}
}
// Ensure an import Weight has been found.
if (importWeight.mWeight == -999.99f) {
System::Print("[ModelImporter] WARNING : Failed to import weight, no appropriate assimpWeight found to import....");
continue;
}
// Tarverse assimp bones and their weights to determine what joint the weight belongs to.
// NOTE: It'd be a better idea to store the aiBone* when building weightList.
std::string parentJointName;
for (uint32_t assimpBoneIndex = 0; assimpBoneIndex < pBoneList.size(); ++assimpBoneIndex) {
const aiBone* assimpBone = pBoneList.at(assimpBoneIndex);
for (uint32_t assimpWeightIndex = 0; assimpWeightIndex < assimpBone->mNumWeights; ++assimpWeightIndex) {
const aiVertexWeight& assimpWeight = assimpBone->mWeights[assimpWeightIndex];
if (assimpWeight.mVertexId == vertexIndex) {
parentJointName = ToCppString(assimpBone->mName);
goto FOUND_PARENT_JOINT_NAME;
}
}
}
FOUND_PARENT_JOINT_NAME:;
// Iterate through joints in pSkeleton til we find one matching parentJointName, this is the parent joint.
for (; weight.m_JointID < pSkeleton.size(); ++weight.m_JointID) {
if (pSkeleton[weight.m_JointID].m_Name == parentJointName) {
break;
}
}
// Import weight bias.
weight.m_Bias = importWeight.mWeight;
// Recover the weight's position from finalVertexPosition, rotate it by the inverse quaternion of the parent joint to recover the weight position.
weight.m_Position = ((finalVertexPosition / weight.m_Bias) - pSkeleton[weight.m_JointID].m_Position).Rotate(AssimpifyQuaternion(pSkeleton[weight.m_JointID].m_Orientation).Inverse());
// Subtract this weight from the finalVertexPosition result. (Note: This is why we are reverse iterating weights.)
finalVertexPosition -= (pSkeleton[weight.m_JointID].m_Position + weight.m_Position) * weight.m_Bias;
}
"ParentBoneName" всегда оказывается неправильным именем соединения. Дайте мне знать, если нужно больше информации, заранее спасибо.