Problem using assimp skeleton animation with directx 11! Wish I can get some help here Hi, I am new to this forum and sorry english isn't my mother language so I will try my my best to explain what's the problem is. I used assimp to import model data and I found a model online and try to import it into my directx 11 project. I successfully render all static model that I have tried on, so I started digging into animation. And the movement ( animation ) of the model is correct but the model looks super weird (which the model looks fine if I don't apply animation on it). From what I have debugged, the vertex data, bone data (bones ID and weights) per vertex are imported correct. So I am thinking is it the matrix problem? void SkinnedMesh::BoneTransform(std::vector& transform, float time) { XMMATRIX parentMatrix = XMMatrixIdentity(); float TicksPerSecond = scene->mAnimations[0]->mTicksPerSecond != 0 ? scene->mAnimations[0]->mTicksPerSecond : 25.0f; float TimeInTicks = time * TicksPerSecond; float AnimationTime = fmod(TimeInTicks, (float)scene->mAnimations[0]->mDuration); ReadNodeHeirarchy(scene->mRootNode, parentMatrix, AnimationTime); transform.resize(bonesCount); for (int i = 0; i < bonesCount; ++i) { transform[i] = bonesMatrix[i].finalMatrix; } } void SkinnedMesh::ReadNodeHeirarchy(const aiNode* node, const XMMATRIX& parentTransform, float animationTime) { std::string nodeName(node->mName.data); const aiAnimation* animation = scene->mAnimations[0]; XMMATRIX NodeTransform = XMMATRIX(&node->mTransformation.a1); const aiNodeAnim* pNodeAnim = findNodeAnimation(animation, nodeName); if (pNodeAnim) { aiVector3D s = interpolateScaling(animationTime, pNodeAnim); XMMATRIX ScalingM = XMMatrixScaling(s.x, s.y, s.z); aiQuaternion q = interpolateRotation(animationTime, pNodeAnim); XMMATRIX RotationM = XMMatrixRotationQuaternion(XMVectorSet(q.x, q.y, q.z, q.w)); aiVector3D t = interpolatePosition(animationTime, pNodeAnim); XMMATRIX TranslationM = XMMatrixTranslation(t.x, t.y, t.z); NodeTransform = ScalingM * RotationM * TranslationM; NodeTransform = XMMatrixTranspose(NodeTransform); } XMMATRIX GlobalTransform = parentTransform * NodeTransform; if (bonesMap.find(nodeName) != bonesMap.end()) { int bone = bonesMap[nodeName]; bonesMatrix[bone].finalMatrix = GlobalInverse * GlobalTransform * bonesMatrix[bone].offsetMatrix; } for (UINT i = 0; i < node->mNumChildren; ++i) { ReadNodeHeirarchy(node->mChildren[i], GlobalTransform, animationTime); } } Here is my Bone Transform and ReadNodeHierarchy function. (which is followed by the openGL tutorial here) float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; weights[0] = input.inBoneWeights[0]; weights[1] = input.inBoneWeights[1]; weights[2] = input.inBoneWeights[2]; weights[3] = 1 - input.inBoneWeights[0] - input.inBoneWeights[1] - input.inBoneWeights[2]; // offset position by bone matrices, using weights to scale float4 p = weights[0] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[0]]); p += weights[1] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[1]]); p += weights[2] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[2]]); p += weights[3] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[3]]); p.w = 1.0f; // offset normal by bone matrices, using weights to scale float4 n = weights[0] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[0]]); n += weights[1] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[1]]); n += weights[2] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[2]]); n += weights[3] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[3]]); n.w = 0.0f; matrix wvp; wvp = mul(World, View); wvp = mul(wvp, Projection); // output.outPosition = mul(float4(input.inPosition, 1.0f), wvp); output.outPosition = mul(p, wvp); And here is my vertex shader for animation. I saw a lot of skeleton model import to directx problems are transpose matrix, but I have tried a lot of times, a lot of different matrix with it or without it, but the problem is still here. So I want to know what the problem is here? Is it transpose matrix or not matrix problem? 3D Viewer 2019-07-28 13-55-13_Trim.mp4 Paverick 2019-07-28 13-53-19_Trim.mp4 https://ift.tt/eA8V8J
Hi, I am new to this forum and sorry english isn't my mother language so I will try my my best to explain what's the problem is. I used assimp to import model data and I found a model online and try to import it into my directx 11 project. I successfully render all static model that I have tried on, so I started digging into animation. And the movement ( animation ) of the model is correct but the model looks super weird (which the model looks fine if I don't apply animation on it). From what I have debugged, the vertex data, bone data (bones ID and weights) per vertex are imported correct. So I am thinking is it the matrix problem? void SkinnedMesh::BoneTransform(std::vector<XMMATRIX>& transform, float time) { XMMATRIX parentMatrix = XMMatrixIdentity(); float TicksPerSecond = scene->mAnimations[0]->mTicksPerSecond != 0 ? scene->mAnimations[0]->mTicksPerSecond : 25.0f; float TimeInTicks = time * TicksPerSecond; float AnimationTime = fmod(TimeInTicks, (float)scene->mAnimations[0]->mDuration); ReadNodeHeirarchy(scene->mRootNode, parentMatrix, AnimationTime); transform.resize(bonesCount); for (int i = 0; i < bonesCount; ++i) { transform[i] = bonesMatrix[i].finalMatrix; } } void SkinnedMesh::ReadNodeHeirarchy(const aiNode* node, const XMMATRIX& parentTransform, float animationTime) { std::string nodeName(node->mName.data); const aiAnimation* animation = scene->mAnimations[0]; XMMATRIX NodeTransform = XMMATRIX(&node->mTransformation.a1); const aiNodeAnim* pNodeAnim = findNodeAnimation(animation, nodeName); if (pNodeAnim) { aiVector3D s = interpolateScaling(animationTime, pNodeAnim); XMMATRIX ScalingM = XMMatrixScaling(s.x, s.y, s.z); aiQuaternion q = interpolateRotation(animationTime, pNodeAnim); XMMATRIX RotationM = XMMatrixRotationQuaternion(XMVectorSet(q.x, q.y, q.z, q.w)); aiVector3D t = interpolatePosition(animationTime, pNodeAnim); XMMATRIX TranslationM = XMMatrixTranslation(t.x, t.y, t.z); NodeTransform = ScalingM * RotationM * TranslationM; NodeTransform = XMMatrixTranspose(NodeTransform); } XMMATRIX GlobalTransform = parentTransform * NodeTransform; if (bonesMap.find(nodeName) != bonesMap.end()) { int bone = bonesMap[nodeName]; bonesMatrix[bone].finalMatrix = GlobalInverse * GlobalTransform * bonesMatrix[bone].offsetMatrix; } for (UINT i = 0; i < node->mNumChildren; ++i) { ReadNodeHeirarchy(node->mChildren[i], GlobalTransform, animationTime); } } Here is my Bone Transform and ReadNodeHierarchy function. (which is followed by the openGL tutorial here) float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; weights[0] = input.inBoneWeights[0]; weights[1] = input.inBoneWeights[1]; weights[2] = input.inBoneWeights[2]; weights[3] = 1 - input.inBoneWeights[0] - input.inBoneWeights[1] - input.inBoneWeights[2]; // offset position by bone matrices, using weights to scale float4 p = weights[0] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[0]]); p += weights[1] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[1]]); p += weights[2] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[2]]); p += weights[3] * mul(float4(input.inPosition, 1.0f), BoneTransform[input.inBoneID[3]]); p.w = 1.0f; // offset normal by bone matrices, using weights to scale float4 n = weights[0] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[0]]); n += weights[1] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[1]]); n += weights[2] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[2]]); n += weights[3] * mul(float4(input.inNormal, 1.0f), BoneTransform[input.inBoneID[3]]); n.w = 0.0f; matrix wvp; wvp = mul(World, View); wvp = mul(wvp, Projection); // output.outPosition = mul(float4(input.inPosition, 1.0f), wvp); output.outPosition = mul(p, wvp); And here is my vertex shader for animation. I saw a lot of skeleton model import to directx problems are transpose matrix, but I have tried a lot of times, a lot of different matrix with it or without it, but the problem is still here. So I want to know what the problem is here? Is it transpose matrix or not matrix problem? 3D Viewer 2019-07-28 13-55-13_Trim.mp4 Paverick 2019-07-28 13-53-19_Trim.mp4
from GameDev.net https://ift.tt/2Mm2poz
from GameDev.net https://ift.tt/2Mm2poz
ليست هناك تعليقات