From 5a0e2be6c67906feb5593f443345777c992d3d6b Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 15 Nov 2024 02:27:38 +0900 Subject: [PATCH] Converter.FromVrm10 --- .../RotateParticle/Editor/Converter.cs | 43 ++++++++++++++++--- .../RotateParticle/Runtime/Components/Warp.cs | 26 ++++++++--- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs index 5f2153c65..f229e82d9 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs @@ -1,3 +1,4 @@ +using System.Linq; using UnityEditor; using UnityEngine; using UniVRM10; @@ -20,12 +21,21 @@ namespace RotateParticle.Components return go.GetComponent() != null; } + /// + /// instance.SpringBone.Springs を rotate particle で置き換える。 + /// UNDO 可能。 + /// [MenuItem(FROM_VRM10_MENU, false)] public static void FromVrm10() { var go = Selection.activeGameObject; var instance = go.GetComponent(); + Undo.IncrementCurrentGroup(); + Undo.SetCurrentGroupName(FROM_VRM10_MENU); + var undo = Undo.GetCurrentGroup(); + + Undo.RegisterCompleteObjectUndo(instance, "RegisterCompleteObjectUndo"); foreach (var spring in instance.SpringBone.Springs) { if (spring.Joints == null || spring.Joints[0] == null) @@ -33,20 +43,43 @@ namespace RotateParticle.Components continue; } - var root = spring.Joints[0].gameObject; - if (root == null) + var root_joint = spring.Joints[0].gameObject; + if (root_joint == null) { continue; } - if (root.GetComponent() != null) + if (root_joint.GetComponent() != null) { continue; } - UnityEditor.Undo.IncrementCurrentGroup(); - UnityEditor.Undo.SetCurrentGroupName("VRM10SpringBoneColliderGroup.Separate"); + var warp = Undo.AddComponent(root_joint); + var joints = spring.Joints.Where(x => x != null).ToArray(); + for (int i = 0; i < joints.Length; ++i) + { + var joint = joints[i]; + warp.Particles.Add(new Warp.Particle + { + OverrideSettings = new Warp.ParticleSettings + { + DragForce = joint.m_dragForce, + GravityDir = joint.m_gravityDir, + GravityPower = joint.m_gravityPower, + StiffnessForce = joint.m_stiffnessForce, + // breaking change from vrm-1.0 + HitRadius = i > 0 ? joints[i - 1].m_jointRadius : joints[i].m_jointRadius, + }, + }); + Undo.DestroyObjectImmediate(joint); + } + spring.Joints.Clear(); } + instance.SpringBone.Springs.Clear(); + + Undo.RegisterFullObjectHierarchyUndo(go, "RegisterFullObjectHierarchyUndo"); + + Undo.CollapseUndoOperations(undo); } } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs index 3be388f61..e2e585130 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs @@ -12,6 +12,20 @@ namespace RotateParticle.Components [Serializable] public class ParticleSettings { + [SerializeField] + public float StiffnessForce = 1.0f; + + [SerializeField] + public float GravityPower = 0; + + [SerializeField] + public Vector3 GravityDir = new Vector3(0, -1.0f, 0); + + [SerializeField, Range(0, 1)] + public float DragForce = 0.4f; + + [SerializeField] + public float HitRadius = 0.02f; } /// @@ -25,29 +39,29 @@ namespace RotateParticle.Components } [SerializeField] - ParticleSettings BaseSettings; + public ParticleSettings BaseSettings; /// /// null のときは world root ではなく model root で処理 /// [SerializeField] - Transform Center; + public Transform Center; /// /// 枝分かれ不可 /// [SerializeField] - List Particles = new List(); + public List Particles = new List(); void Reset() { - Debug.Log("Warp.Reset"); + // Debug.Log("Warp.Reset"); } void OnValidate() { - // 枝分かれを削除 - Debug.Log("Warp.OnValidate"); + // TODO: 枝分かれを削除 + // Debug.Log("Warp.OnValidate"); } } }