feat: update
This commit is contained in:
parent
0068506cfe
commit
826543d876
BIN
build/FBX2glTF
BIN
build/FBX2glTF
Binary file not shown.
|
@ -830,11 +830,43 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
const FbxVector4 baseTranslation = baseTransform.GetT();
|
const FbxVector4 baseTranslation = baseTransform.GetT();
|
||||||
const FbxQuaternion baseRotation = baseTransform.GetQ();
|
const FbxQuaternion baseRotation = baseTransform.GetQ();
|
||||||
const FbxVector4 baseScaling = computeLocalScale(pNode);
|
const FbxVector4 baseScaling = computeLocalScale(pNode);
|
||||||
bool hasTranslation = false;
|
FbxAnimCurveNode* translationCurveNode = pNode->LclTranslation.GetCurveNode();
|
||||||
bool hasRotation = false;
|
FbxAnimCurveNode* rotationCurveNode = pNode->LclRotation.GetCurveNode();
|
||||||
bool hasScale = false;
|
FbxAnimCurveNode* scalingCurveNode = pNode->LclScaling.GetCurveNode();
|
||||||
|
|
||||||
|
bool hasTranslation = !!translationCurveNode;
|
||||||
|
bool hasRotation = !!rotationCurveNode;
|
||||||
|
bool hasScale = !!scalingCurveNode;
|
||||||
bool hasMorphs = false;
|
bool hasMorphs = false;
|
||||||
|
|
||||||
|
FbxMesh* mesh = pNode->GetMesh();
|
||||||
|
if (mesh) {
|
||||||
|
int deformerCount = mesh->GetDeformerCount(FbxDeformer::eBlendShape);
|
||||||
|
for (int i = 0; i < deformerCount; ++i) {
|
||||||
|
FbxBlendShape* blendShape = static_cast<FbxBlendShape*>(mesh->GetDeformer(i, FbxDeformer::eBlendShape));
|
||||||
|
int channelCount = blendShape->GetBlendShapeChannelCount();
|
||||||
|
for (int j = 0; j < channelCount; ++j) {
|
||||||
|
FbxBlendShapeChannel* channel = blendShape->GetBlendShapeChannel(j);
|
||||||
|
if (channel && channel->GetTargetShapeCount() > 0) {
|
||||||
|
for (int layerIx = 0; layerIx < pAnimStack->GetMemberCount(); layerIx++) {
|
||||||
|
FbxAnimLayer* layer = pAnimStack->GetMember<FbxAnimLayer>(layerIx);
|
||||||
|
FbxAnimCurve* curve = mesh->GetShapeChannel(i, j, layer);
|
||||||
|
if (curve) {
|
||||||
|
hasMorphs = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasMorphs) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasMorphs) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RawChannel channel;
|
RawChannel channel;
|
||||||
channel.nodeIndex = raw.GetNodeById(pNode->GetUniqueID());
|
channel.nodeIndex = raw.GetNodeById(pNode->GetUniqueID());
|
||||||
|
|
||||||
|
@ -847,21 +879,6 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
const FbxQuaternion localRotation = localTransform.GetQ();
|
const FbxQuaternion localRotation = localTransform.GetQ();
|
||||||
const FbxVector4 localScale = computeLocalScale(pNode, pTime);
|
const FbxVector4 localScale = computeLocalScale(pNode, pTime);
|
||||||
|
|
||||||
|
|
||||||
hasTranslation |=
|
|
||||||
(fabs(localTranslation[0] - baseTranslation[0]) > epsilon ||
|
|
||||||
fabs(localTranslation[1] - baseTranslation[1]) > epsilon ||
|
|
||||||
fabs(localTranslation[2] - baseTranslation[2]) > epsilon);
|
|
||||||
hasRotation |=
|
|
||||||
(fabs(localRotation[0] - baseRotation[0]) > epsilon ||
|
|
||||||
fabs(localRotation[1] - baseRotation[1]) > epsilon ||
|
|
||||||
fabs(localRotation[2] - baseRotation[2]) > epsilon ||
|
|
||||||
fabs(localRotation[3] - baseRotation[3]) > epsilon);
|
|
||||||
hasScale |=
|
|
||||||
(fabs(localScale[0] - baseScaling[0]) > epsilon ||
|
|
||||||
fabs(localScale[1] - baseScaling[1]) > epsilon ||
|
|
||||||
fabs(localScale[2] - baseScaling[2]) > epsilon);
|
|
||||||
|
|
||||||
channel.translations.push_back(toVec3f(localTranslation) * scaleFactor);
|
channel.translations.push_back(toVec3f(localTranslation) * scaleFactor);
|
||||||
channel.rotations.push_back(toQuatf(localRotation));
|
channel.rotations.push_back(toQuatf(localRotation));
|
||||||
channel.scales.push_back(toVec3f(localScale));
|
channel.scales.push_back(toVec3f(localScale));
|
||||||
|
@ -915,7 +932,6 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
if (!std::isnan(result)) {
|
if (!std::isnan(result)) {
|
||||||
// we're transitioning into targetIx
|
// we're transitioning into targetIx
|
||||||
channel.weights.push_back(result);
|
channel.weights.push_back(result);
|
||||||
hasMorphs = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (targetIx != targetCount - 1) {
|
if (targetIx != targetCount - 1) {
|
||||||
|
@ -923,7 +939,6 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
if (!std::isnan(result)) {
|
if (!std::isnan(result)) {
|
||||||
// we're transitioning AWAY from targetIx
|
// we're transitioning AWAY from targetIx
|
||||||
channel.weights.push_back(1.0f - result);
|
channel.weights.push_back(1.0f - result);
|
||||||
hasMorphs = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -937,20 +952,18 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!optAnimation || hasTranslation || hasRotation || hasScale || hasMorphs) {
|
if (hasTranslation || hasRotation || hasScale || hasMorphs) {
|
||||||
if (optAnimation) {
|
if (!hasTranslation) {
|
||||||
if (!hasTranslation) {
|
channel.translations.clear();
|
||||||
channel.translations.clear();
|
}
|
||||||
}
|
if (!hasRotation) {
|
||||||
if (!hasRotation) {
|
channel.rotations.clear();
|
||||||
channel.rotations.clear();
|
}
|
||||||
}
|
if (!hasScale) {
|
||||||
if (!hasScale) {
|
channel.scales.clear();
|
||||||
channel.scales.clear();
|
}
|
||||||
}
|
if (!hasMorphs) {
|
||||||
if (!hasMorphs) {
|
channel.weights.clear();
|
||||||
channel.weights.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
animation.channels.emplace_back(channel);
|
animation.channels.emplace_back(channel);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue