allow partial morph animations

This commit is contained in:
Nick Fisher
2023-08-18 15:43:20 +08:00
parent 46ecacde12
commit ed72c16724
13 changed files with 174 additions and 135 deletions

View File

@@ -272,12 +272,16 @@ void AssetManager::updateAnimations() {
if(anim.mReverse) {
frameNumber = lengthInFrames - frameNumber;
}
// set the weights appropriately
rm.setMorphWeights(
rm.getInstance(asset.mMorphAnimationBuffer.mMeshTarget),
asset.mMorphAnimationBuffer.mFrameData.data() + (frameNumber * asset.mMorphAnimationBuffer.mNumMorphWeights),
asset.mMorphAnimationBuffer.mNumMorphWeights
);
auto baseOffset = frameNumber * asset.mMorphAnimationBuffer.mMorphIndices.size();
for(auto morphIndex : asset.mMorphAnimationBuffer.mMorphIndices) {
// set the weights appropriately
rm.setMorphWeights(
rm.getInstance(asset.mMorphAnimationBuffer.mMeshTarget),
asset.mMorphAnimationBuffer.mFrameData.data() + baseOffset + morphIndex,
1,
morphIndex
);
}
break;
}
case AnimationType::BONE: {
@@ -416,7 +420,8 @@ bool AssetManager::setMorphAnimationBuffer(
EntityId entityId,
const char* entityName,
const float* const morphData,
int numMorphWeights,
const int* const morphIndices,
int numMorphTargets,
int numFrames,
float frameLengthInMs) {
@@ -438,10 +443,13 @@ bool AssetManager::setMorphAnimationBuffer(
asset.mMorphAnimationBuffer.mFrameData.insert(
asset.mMorphAnimationBuffer.mFrameData.begin(),
morphData,
morphData + (numFrames * numMorphWeights)
morphData + (numFrames * numMorphTargets)
);
asset.mMorphAnimationBuffer.mFrameLengthInMs = frameLengthInMs;
asset.mMorphAnimationBuffer.mNumMorphWeights = numMorphWeights;
asset.mMorphAnimationBuffer.mMorphIndices.resize(numMorphTargets);
for(int i =0; i< numMorphTargets; i++) {
asset.mMorphAnimationBuffer.mMorphIndices[i] = morphIndices[i];
}
AnimationStatus animation;
animation.mDuration = (frameLengthInMs * numFrames) / 1000.0f;