mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 21:34:38 -05:00
Merge pull request #2630 from ousttrue/fix/vrm0x_spring_dup_joints
[0.x][SpringBone] Avoid resetting indexmaps causing exceptions
This commit is contained in:
@@ -38,7 +38,15 @@ namespace VRM.SpringBone
|
||||
|
||||
for (int i = 0; i < m_joints.Count; ++i)
|
||||
{
|
||||
m_jointIndexMap.Add(m_joints[i].Item1, i);
|
||||
// #2617
|
||||
// Keys may not be unique
|
||||
m_jointIndexMap[m_joints[i].Item1] = i;
|
||||
|
||||
// this index refer m_joints
|
||||
// if not unique,
|
||||
// m_joints[] = { (a, a_state), (b, b_state), (a, a_state) ... };
|
||||
// m_joints[0] and m_joints[2] is same.
|
||||
// The above code is ok
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
Assets/VRM/Tests/VRMSpringBoneTests.cs
Normal file
31
Assets/VRM/Tests/VRMSpringBoneTests.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public class VRMSpringBoneTests
|
||||
{
|
||||
static string AliciaPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetFullPath(Application.dataPath + "/../Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm")
|
||||
.Replace("\\", "/");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DuplicatedJoints()
|
||||
{
|
||||
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
|
||||
var sb = loaded.GetComponentInChildren<VRMSpringBone>();
|
||||
|
||||
// make duplicate #2617
|
||||
sb.RootBones.Add(sb.RootBones[0].GetChild(0));
|
||||
|
||||
Assert.DoesNotThrow(() => sb.Setup());
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM/Tests/VRMSpringBoneTests.cs.meta
Normal file
11
Assets/VRM/Tests/VRMSpringBoneTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e52c8edc85e2460489f05eebc7f1f201
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user