diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs b/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs
index 8141a5784..852ebda19 100644
--- a/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs
+++ b/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs
@@ -70,22 +70,53 @@ namespace UniVRM10
void MigrateRootBone(JsonNode y)
{
var rootBoneIndex = y.GetInt32();
- CreateJointsRecursive(CreateSpring(), _gltf.nodes[rootBoneIndex]);
+ if (rootBoneIndex >= 0 && rootBoneIndex < _gltf.nodes.Count)
+ {
+ // root
+ CreateJointsRecursive(_gltf.nodes[rootBoneIndex], 1);
+ }
}
- void CreateJointsRecursive(UniGLTF.Extensions.VRMC_springBone.Spring spring, UniGLTF.glTFNode node)
+ ///
+ ///
+ ///
+ ///
+ /// children[0] のみカウントアップする。その他は0にリセットする
+ ///
+ void CreateJointsRecursive(UniGLTF.glTFNode node, int level, UniGLTF.Extensions.VRMC_springBone.Spring spring = null)
{
- spring.Joints.Add(CreateJoint(_gltf.nodes.IndexOf(node)));
+ if (spring == null && level > 0)
+ {
+ // 2番目以降の子ノードの子から新しい Spring を作る。
+ spring = CreateSpring();
+ }
+ if (spring != null)
+ {
+ // level==0 のとき(2番目以降の兄弟ボーン)は飛ばす
+ spring.Joints.Add(CreateJoint(_gltf.nodes.IndexOf(node)));
+ }
if (node.children != null && node.children.Length > 0)
{
- // 先頭の子ノードを追加する
- CreateJointsRecursive(spring, _gltf.nodes[node.children[0]]);
-
- for (int i = 1; i < node.children.Length; ++i)
+ for (int i = 0; i < node.children.Length; ++i)
{
- // 2番目以降の子ノードの子から新しい Spring を作る。
var childIndex = node.children[i];
+ if (childIndex < 0 || childIndex >= _gltf.nodes.Count)
+ {
+ // -1 など?
+ continue;
+ }
+
+ if (i == 0)
+ {
+ // spring に joint を追加する
+ CreateJointsRecursive(_gltf.nodes[childIndex], level + 1, spring);
+ }
+ else
+ {
+ // 再帰
+ CreateJointsRecursive(_gltf.nodes[childIndex], 0);
+ }
}
}
else