The final set skeleton call destroys and rebuilds the GPU bone reso… (#359)

* The final `set skeleton` call destroys and rebuilds the GPU bone resources that were bound in the previous two steps. However, the descriptor set is not rebound. As a result, the draw call for this subModel cannot access the bone matrices, so the entire character fails to render (this is not vertex deformation; the character does not appear at all). The fix should replace the reference in `descriptor.buffer` with the new buffer, mark it dirty, and lazily rebuild the descriptor before the next draw.

* opt
This commit is contained in:
llsansun
2026-09-23 16:18:03 +08:00
committed by GitHub
parent 661de759ef
commit f620989ce7
4 changed files with 35 additions and 0 deletions
+7
View File
@@ -106,6 +106,13 @@ export class BakedSkinningModel extends MorphModel {
UBOSkinningTexture.SIZE,
));
}
// The animation buffer belongs to the skinning root. Refresh its binding without
// rebuilding the instanced attribute block, which would erase custom attribute values.
for (let i = 0; i < this._subModels.length; i++) {
this._updateLocalDescriptors(i, this._subModels[i].descriptorSet);
}
this.updateInstancedJointTextureInfo();
}
// Override
+10
View File
@@ -142,6 +142,7 @@ export class SkinningModel extends MorphModel {
}
this._bufferIndices = null; this._joints.length = 0;
if (!skeleton || !skinningRoot || !mesh) { return; }
const prevRealTimeTextureMode = this._realTimeTextureMode;
this._realTimeTextureMode = false;
if (UBOSkinning.JOINT_UNIFORM_CAPACITY < skeleton.joints.length) { this._realTimeTextureMode = true; }
this.transform = skinningRoot;
@@ -161,6 +162,15 @@ export class SkinningModel extends MorphModel {
if (!jointMaps) { indices.push(index); buffers.push(0); } else { getRelevantBuffers(indices, buffers, jointMaps, index); }
this._joints.push({ indices, buffers, bound, target, bindpose, transform });
}
// Rebind recreated joint resources without resetting user-provided instanced attributes.
const subModelCount = Math.min(this._subModels.length, this._bufferIndices.length);
if (subModelCount && prevRealTimeTextureMode !== this._realTimeTextureMode) {
this.onMacroPatchesStateChanged();
}
for (let i = 0; i < subModelCount; i++) {
this._updateLocalDescriptors(i, this._subModels[i].descriptorSet);
}
}
/**
@@ -86,6 +86,12 @@ void BakedSkinningModel::bindSkeleton(Skeleton *skeleton, Node *skinningRoot, Me
pipeline::UBOSkinning::size,
});
}
// JSB synchronizes the new root's animation buffer before calling bindSkeleton.
for (index_t i = 0; i < _subModels.size(); ++i) {
updateLocalDescriptors(i, _subModels[i]->getDescriptorSet());
}
updateInstancedJointTextureInfo();
}
void BakedSkinningModel::updateTransform(uint32_t stamp) {
+12
View File
@@ -23,6 +23,8 @@
****************************************************************************/
#include "3d/models/SkinningModel.h"
#include <algorithm>
#include <utility>
#include "3d/assets/Mesh.h"
@@ -80,6 +82,7 @@ void SkinningModel::bindSkeleton(Skeleton *skeleton, Node *skinningRoot, Mesh *m
_joints.clear();
if (!skeleton || !skinningRoot || !mesh) return;
const bool prevRealTimeTextureMode = _realTimeTextureMode;
auto jointCount = static_cast<uint32_t>(skeleton->getJoints().size());
_realTimeTextureMode = pipeline::SkinningJointCapacity::jointUniformCapacity < jointCount;
setTransform(skinningRoot);
@@ -113,6 +116,15 @@ void SkinningModel::bindSkeleton(Skeleton *skeleton, Node *skinningRoot, Mesh *m
jointInfo.indices = std::move(indices);
_joints.emplace_back(std::move(jointInfo));
}
// Rebind recreated resources without resetting custom instanced attributes.
const auto subModelCount = std::min(_subModels.size(), _bufferIndices.size());
if (subModelCount && prevRealTimeTextureMode != _realTimeTextureMode) {
onMacroPatchesStateChanged();
}
for (index_t i = 0; i < subModelCount; ++i) {
updateLocalDescriptors(i, _subModels[i]->getDescriptorSet());
}
}
void SkinningModel::updateTransform(uint32_t stamp) {