diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroupDrawer.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroupDrawer.cs new file mode 100644 index 000000000..3159fd8fd --- /dev/null +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroupDrawer.cs @@ -0,0 +1,22 @@ + +using UnityEditor; +using UnityEngine; + +namespace UniVRM10 +{ + [CustomPropertyDrawer(typeof(VRM10SpringBoneColliderGroup))] + public class VRM10SpringBoneColliderGroupDrawer : PropertyDrawer + { + public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) + { + try + { + EditorGUI.ObjectField(rect, property, new GUIContent(((VRM10SpringBoneColliderGroup)property.objectReferenceValue).Name)); + } + catch + { + EditorGUI.ObjectField(rect, property, new GUIContent("fallback")); + } + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroupDrawer.cs.meta b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroupDrawer.cs.meta new file mode 100644 index 000000000..e144f3f0f --- /dev/null +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroupDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9f5afdd3051fad24e9c7cb8caa29dc7f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 640e3afc5..e3a608e8b 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -554,6 +554,7 @@ namespace UniVRM10 foreach (var g in gltfVrmSpringBone.ColliderGroups) { var colliderGroup = secondary.gameObject.AddComponent(); + colliderGroup.Name = g.Name; controller.SpringBone.ColliderGroups.Add(colliderGroup); if (g != null && g.Colliders != null) diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs b/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs index ff2f6400f..a298ed352 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using UniGLTF.Extensions.VRMC_springBone; using UniJSON; @@ -48,6 +49,23 @@ namespace UniVRM10 MigrateRootBone(vrm0Bone.GetInt32()); } } + + // fallback. default spring names + foreach (var spring in _springs) + { + if (string.IsNullOrEmpty(spring.Name) && spring.Joints.Count > 0 && spring.Joints[0].Node.HasValue) + { + var i = spring.Joints[0].Node.Value; + if (i >= 0 && i < _gltf.nodes.Count) + { + spring.Name = _gltf.nodes[i].name; + } + } + } + if (string.IsNullOrEmpty(_comment) && _springs.Count > 0) + { + _comment = _springs[0].Name; + } } Spring CreateSpring() @@ -263,6 +281,15 @@ namespace UniVRM10 { Colliders = colliderIndices.ToArray(), }; + if (colliderGroup.Colliders.Length > 0 && springBone.Colliders[colliderGroup.Colliders[0]].Node.HasValue) + { + var i = springBone.Colliders[colliderGroup.Colliders[0]].Node.Value; + if (i >= 0 && i < gltf.nodes.Count) + { + var node = gltf.nodes[i]; + colliderGroup.Name = node.name; + } + } springBone.ColliderGroups.Add(colliderGroup); }