Skip to content

Commit

Permalink
Merge pull request #2253 from ousttrue/fix/vrm10_springbone_inspector…
Browse files Browse the repository at this point in the history
…_migration

[vrm10] SpringBone の inspector 修正など
  • Loading branch information
ousttrue committed Feb 27, 2024
2 parents f7aaef0 + 712b35c commit dad8305
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Assets/VRM10/Runtime/IO/Vrm10Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ async Task LoadSpringBoneAsync(IAwaitCaller awaitCaller, Vrm10Instance controlle
foreach (var g in gltfVrmSpringBone.ColliderGroups)
{
var colliderGroup = secondary.gameObject.AddComponent<VRM10SpringBoneColliderGroup>();
colliderGroup.Name = g.Name;
controller.SpringBone.ColliderGroups.Add(colliderGroup);

if (g != null && g.Colliders != null)
Expand Down
29 changes: 28 additions & 1 deletion Assets/VRM10/Runtime/Migration/MigrationVrmSpringBone.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using UniGLTF.Extensions.VRMC_springBone;
using UniJSON;
Expand Down Expand Up @@ -48,6 +49,23 @@ public SpringBoneGroupMigrator(UniGLTF.glTF gltf, JsonNode vrm0BoneGroup)
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()
Expand Down Expand Up @@ -263,6 +281,15 @@ public static VRMC_springBone Migrate(UniGLTF.glTF gltf, JsonNode vrm0)
{
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);
}

Expand Down

0 comments on commit dad8305

Please sign in to comment.