I have some models that share one babylon file and single skeleton.
Think various selectable hair styles like this:
avatar.babylon
- torsoMesh
- headMesh
- hair1Mesh
- hair2Mesh
- hair3Mesh
- skeleton
All the meshes are assigned the same skeleton.
I am trying to load them like this:
const i = assetContainer.instantiateModelsToScene(name => name, false, {
predicate: entity => ["torsoMesh", "headMesh", "hair1Mesh", "skeleton"].includes(entity.name)
});
Please note, that only one of the 3 hair styles in selected in the predicate.
In such a situation (a skeleton is instantiated, but some meshes that have that skeleton assigned are not), instantiateModelsToScene() crashes here, because copy is not defined
for (const m of this.meshes) {
if (m.skeleton === s && !m.isAnInstance) {
const copy = storeMap[conversionMap[m.uniqueId]] as Mesh;
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
if (copy.isAnInstance) {
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
continue;
}
copy.skeleton = clone;
if (alreadySwappedSkeletons.indexOf(clone) !== -1) {
continue;
}
alreadySwappedSkeletons.push(clone);
// Check if bones are mesh linked
for (const bone of clone.bones) {
if (bone._linkedTransformNode) {
bone._linkedTransformNode = storeMap[conversionMap[bone._linkedTransformNode.uniqueId]];
}
}
}
}
I believe that checking if copy is null should be enough to fix it.
I am sorry I can not share the concrete model, but the playground below demonstrates the crash.