From c75dd199a50adcf9f3add24af8d4810511f52dc0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 03:24:02 +0900 Subject: [PATCH 01/25] UseJob default true --- .../ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs index 9bfa68d8b..c90d025b7 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; -using UniVRM10; + namespace UniVRM10.ClothWarp.Components { @@ -17,7 +17,7 @@ namespace UniVRM10.ClothWarp.Components public List Cloths = new(); [SerializeField] - public bool UseJob; + public bool UseJob = true; IVrm10SpringBoneRuntime m_runtime; public IVrm10SpringBoneRuntime CreateSpringBoneRuntime() From ffb1f54bdd20a05abb9a8bb53c074397cca5daab Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 03:24:14 +0900 Subject: [PATCH 02/25] update RotateParticleRuntimeProviderEditor --- .../RotateParticleRuntimeProviderEditor.cs | 81 ++++++++++++------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs index f1c12601a..320595292 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs @@ -1,7 +1,6 @@ -using System.Linq; +using UnityEngine.UIElements; using UnityEditor; -using UnityEngine; -using UniVRM10; +using UnityEditor.UIElements; namespace UniVRM10.ClothWarp.Components @@ -11,58 +10,78 @@ namespace UniVRM10.ClothWarp.Components { const string FROM_VRM10_MENU = "Replace VRM10 Springs to ClothWarp Warps"; - [MenuItem(FROM_VRM10_MENU, true)] - public static bool IsFromVrm10() + ClothWarpRuntimeProvider _target; + Vrm10Instance _vrm; + + void OnEnable() { - var go = Selection.activeGameObject; - if (go == null) + _target = (ClothWarpRuntimeProvider)target; + if (_target != null) { - return false; + _vrm = _target.GetComponent(); } - return go.GetComponent() != null; } - public override void OnInspectorGUI() + public override VisualElement CreateInspectorGUI() { - var provider = target as ClothWarpRuntimeProvider; - if (provider == null) + var root = new VisualElement(); + root.Bind(serializedObject); { - return; + var s = new PropertyField { bindingPath = "m_Script" }; + s.SetEnabled(false); + root.Add(s); } - var instance = provider.GetComponent(); - using (new EditorGUI.DisabledScope(instance == null)) + root.Add(new PropertyField { bindingPath = nameof(_target.Warps) }); + root.Add(new PropertyField { bindingPath = nameof(_target.Cloths) }); + { - if (GUILayout.Button("Replace VRM10 Springs to ClothWarp Warps")) + var setup = new Foldout { text = "Setup" }; + + var from_vrm10 = new Button { text = "Replace VRM10 Springs to ClothWarp Warps" }; + setup.Add(from_vrm10); + from_vrm10.RegisterCallback(e => { Undo.IncrementCurrentGroup(); Undo.SetCurrentGroupName(FROM_VRM10_MENU); var undo = Undo.GetCurrentGroup(); - Undo.RegisterCompleteObjectUndo(instance, "RegisterCompleteObjectUndo"); - ClothWarpRuntimeProvider.FromVrm10(instance, Undo.AddComponent, Undo.DestroyObjectImmediate); - Undo.RegisterFullObjectHierarchyUndo(instance.gameObject, "RegisterFullObjectHierarchyUndo"); + Undo.RegisterCompleteObjectUndo(_vrm, "RegisterCompleteObjectUndo"); + ClothWarpRuntimeProvider.FromVrm10(_vrm, Undo.AddComponent, Undo.DestroyObjectImmediate); + Undo.RegisterFullObjectHierarchyUndo(_vrm.gameObject, "RegisterFullObjectHierarchyUndo"); - Undo.RegisterCompleteObjectUndo(provider, "RegisterCompleteObjectUndo"); - provider.Reset(); + Undo.RegisterCompleteObjectUndo(_target, "RegisterCompleteObjectUndo"); + _target.Reset(); Undo.CollapseUndoOperations(undo); - } - } + }); - using (new EditorGUI.DisabledScope(instance == null || !Application.isPlaying)) - { - if (GUILayout.Button("RestoreInitialTransform")) + var reload = new Button { text = "Reload" }; + setup.Add(reload); + reload.RegisterCallback(e => { - instance.Runtime.SpringBone.RestoreInitialTransform(); - } + _target.Reset(); + }); + + root.Add(setup); } - if (GUILayout.Button("Reset")) { - provider.Reset(); + // runtime: reset button + var runtime = new Foldout { text = "Runtime" }; + root.Add(runtime); + + var button = new Button + { + text = "RestoreInitialTransform", + }; + runtime.Add(button); + button.RegisterCallback((e) => + { + _vrm.Runtime.SpringBone.RestoreInitialTransform(); + }); } - base.OnInspectorGUI(); + return root; } } } \ No newline at end of file From 6018af0a4e15ccf78d861bd19ca2da0813d18cf3 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 03:58:24 +0900 Subject: [PATCH 03/25] fix ClothWarpRoot.OnValidate --- .../ClothWarp/Runtime/Components/ClothWarpRoot.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRoot.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRoot.cs index fa3b708c0..456a8c3a8 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRoot.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRoot.cs @@ -4,7 +4,6 @@ using System.Linq; using UniGLTF.SpringBoneJobs.Blittables; using UnityEngine; using UnityEngine.UIElements; -using UniVRM10; namespace UniVRM10.ClothWarp.Components @@ -100,7 +99,18 @@ namespace UniVRM10.ClothWarp.Components void OnValidate() { - m_particles = GetComponentsInChildren().Skip(1).Select(x => new Particle(x)).ToList(); + var backup = m_particles.ToDictionary(x => x.Transform, x => x); + m_particles = GetComponentsInChildren().Skip(1).Select(x => + { + foreach (var particle in m_particles) + { + if (particle.Transform == x) + { + return particle; + } + } + return new Particle(x); + }).ToList(); m_map.Clear(); for (int i = 0; i < m_particles.Count; ++i) { From 9773b0c915f79a42a868c22fa4948bf077b6d21c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 03:58:34 +0900 Subject: [PATCH 04/25] rename --- .../Editor/{WarpRootEditor.cs => ClothWarpRootEditor.cs} | 2 +- .../{WarpRootEditor.cs.meta => ClothWarpRootEditor.cs.meta} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/{WarpRootEditor.cs => ClothWarpRootEditor.cs} (99%) rename Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/{WarpRootEditor.cs.meta => ClothWarpRootEditor.cs.meta} (100%) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/WarpRootEditor.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs similarity index 99% rename from Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/WarpRootEditor.cs rename to Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs index 44f81cae6..2af75f659 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/WarpRootEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs @@ -10,7 +10,7 @@ using UniVRM10; namespace UniVRM10.ClothWarp.Components { [CustomEditor(typeof(ClothWarpRoot))] - class WarpRootEditor : Editor + class ClothWarpRootEditor : Editor { private ClothWarpRoot m_target; private Vrm10Instance m_vrm; diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/WarpRootEditor.cs.meta b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs.meta similarity index 100% rename from Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/WarpRootEditor.cs.meta rename to Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs.meta From 95d5576cc81c91099d19189708e787041bb6514a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 11:06:47 +0900 Subject: [PATCH 05/25] fix StrandCollisionJob --- .../ClothSample/ClothWarp/Runtime/Jobs/Collision.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs index 1f572cd4f..71966a434 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs @@ -59,8 +59,8 @@ namespace UniVRM10.ClothWarp.Jobs pos += l.GetDelta(c.radius); } } - StrandCollision[particleIndex] = pos; } + StrandCollision[particleIndex] = pos; } } @@ -312,8 +312,8 @@ namespace UniVRM10.ClothWarp.Jobs } else { - NextPosition[particleIndex] = StrandCollision[particleIndex]; + NextPosition[particleIndex] = StrandCollision[particleIndex]; + } } } - } } \ No newline at end of file From d21ac212d9e93966c551ae599042415f703b40bb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 13:40:01 +0900 Subject: [PATCH 06/25] Replace split to Load and Clear --- .../ClothSample/ClothViewer/ClothViewerUI.cs | 3 +- .../ClothWarp/Editor/ClothWarpRootEditor.cs | 38 +++++----------- .../RotateParticleRuntimeProviderEditor.cs | 44 +++++++++++++++---- .../ClothWarp/Runtime/ClothWarpRuntime.cs | 3 ++ .../Components/ClothWarpRuntimeProvider.cs | 10 +---- .../Runtime/Jobs/ClothWarpJobRuntime.cs | 12 ++++- .../ClothWarp/Runtime/Jobs/Particle.cs | 13 +++--- 7 files changed, 72 insertions(+), 51 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs index 5473dc515..7edcdfcca 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs @@ -402,8 +402,7 @@ namespace UniVRM10.Cloth.Viewer else { ClothWarpRuntimeProvider.FromVrm10(vrm, - go => go.AddComponent(), - o => GameObject.DestroyImmediate(o)); + go => go.AddComponent()); } if (animator.GetBoneTransform(HumanBodyBones.Hips) is var hips) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs index 2af75f659..4b902d18b 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/ClothWarpRootEditor.cs @@ -27,26 +27,6 @@ namespace UniVRM10.ClothWarp.Components m_vrm = m_target.GetComponentInParent(); } - // public override void OnInspectorGUI() - // { - // var n = EditorUtility.GetDirtyCount(m_target.GetInstanceID()); - // base.OnInspectorGUI(); - // if (n != EditorUtility.GetDirtyCount(m_target.GetInstanceID())) - // { - // if (m_vrm != null) - // { - // if (Application.isPlaying) - // { - // m_vrm.Runtime.SpringBone.SetJointLevel(m_target.transform, m_target.BaseSettings); - // foreach (var p in m_target.Particles) - // { - // m_vrm.Runtime.SpringBone.SetJointLevel(p.Transform, p.GetSettings(m_target.BaseSettings)); - // } - // } - // } - // } - // } - void BindColumn(string title, int width, Func makeVisualELmeent, Func enableFunc, string subpath) where T : BindableElement { m_treeview.columns.Add(new Column @@ -116,15 +96,19 @@ namespace UniVRM10.ClothWarp.Components private void OnValueChanged(SerializedObject so) { - Debug.Log("Name changed: " + so.targetObject.name); - // var nameProperty = so.FindProperty("m_Name"); + if (m_vrm != null) + { + if (Application.isPlaying) + { + m_vrm.Runtime.SpringBone.SetJointLevel(m_target.transform, m_target.BaseSettings); + foreach (var p in m_target.Particles) + { + m_vrm.Runtime.SpringBone.SetJointLevel(p.Transform, p.Settings); + } + } + } - // if (nameProperty.stringValue.Contains(" ")) - // _textField.style.backgroundColor = Color.red; - // else - // _textField.style.backgroundColor = StyleKeyword.Null; m_treeview.RefreshItems(); - // m_treeview.SetRootItems(m_target.m_rootitems); Repaint(); } diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs index 320595292..5b935b7e9 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs @@ -8,8 +8,6 @@ namespace UniVRM10.ClothWarp.Components [CustomEditor(typeof(ClothWarpRuntimeProvider))] public class RotateParticleRuntimeProviderEditor : Editor { - const string FROM_VRM10_MENU = "Replace VRM10 Springs to ClothWarp Warps"; - ClothWarpRuntimeProvider _target; Vrm10Instance _vrm; @@ -37,21 +35,51 @@ namespace UniVRM10.ClothWarp.Components { var setup = new Foldout { text = "Setup" }; - var from_vrm10 = new Button { text = "Replace VRM10 Springs to ClothWarp Warps" }; + var from_vrm10 = new Button { text = "Load VRM10 Springs to ClothWarp Warps" }; setup.Add(from_vrm10); from_vrm10.RegisterCallback(e => { Undo.IncrementCurrentGroup(); - Undo.SetCurrentGroupName(FROM_VRM10_MENU); + Undo.SetCurrentGroupName("Load Vrm-1.0 Springs to ClothWarp Warps"); + var undo = Undo.GetCurrentGroup(); + + // attach ClothWarp from VRM10Instance.Springs + ClothWarpRuntimeProvider.FromVrm10(_vrm, Undo.AddComponent); + Undo.RegisterFullObjectHierarchyUndo(_vrm.gameObject, "RegisterFullObjectHierarchyUndo"); + + // update ClothWarpRuntimeProvider + Undo.RegisterCompleteObjectUndo(_target, "RegisterCompleteObjectUndo"); + _target.Reset(); + + Undo.CollapseUndoOperations(undo); + }); + + var clear_vrm10_springs = new Button { text = "Clear Vrm-1.0 springs" }; + setup.Add(clear_vrm10_springs); + clear_vrm10_springs.RegisterCallback(e => + { + Undo.IncrementCurrentGroup(); + Undo.SetCurrentGroupName("Clear VRM10 Srpings"); var undo = Undo.GetCurrentGroup(); Undo.RegisterCompleteObjectUndo(_vrm, "RegisterCompleteObjectUndo"); - ClothWarpRuntimeProvider.FromVrm10(_vrm, Undo.AddComponent, Undo.DestroyObjectImmediate); + foreach (var spring in _vrm.SpringBone.Springs) + { + if (spring != null) + { + foreach (var joint in spring.Joints) + { + if (joint != null) + { + Undo.DestroyObjectImmediate(joint); + } + } + } + spring.Joints.Clear(); + } + _vrm.SpringBone.Springs.Clear(); Undo.RegisterFullObjectHierarchyUndo(_vrm.gameObject, "RegisterFullObjectHierarchyUndo"); - Undo.RegisterCompleteObjectUndo(_target, "RegisterCompleteObjectUndo"); - _target.Reset(); - Undo.CollapseUndoOperations(undo); }); diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/ClothWarpRuntime.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/ClothWarpRuntime.cs index 63888a4d6..ed13969c8 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/ClothWarpRuntime.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/ClothWarpRuntime.cs @@ -11,6 +11,9 @@ using UnityEngine; namespace UniVRM10.ClothWarp { + /// + /// プロトタイプ。非 job + /// public class ClothWarpRuntime : IVrm10SpringBoneRuntime { Vrm10Instance _vrm; diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs index c90d025b7..6c238e2d3 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Components/ClothWarpRuntimeProvider.cs @@ -45,8 +45,7 @@ namespace UniVRM10.ClothWarp.Components } public static void FromVrm10(Vrm10Instance instance, - Func addWarp, - Action deleteObject) + Func addWarp) { foreach (var spring in instance.SpringBone.Springs) { @@ -64,7 +63,6 @@ namespace UniVRM10.ClothWarp.Components var warp = root_joint.GetComponent(); if (warp == null) { - // var warp = Undo.AddComponent(root_joint); warp = addWarp(root_joint); var joints = spring.Joints.Where(x => x != null).ToArray(); for (int i = 0; i < joints.Length; ++i) @@ -76,7 +74,7 @@ namespace UniVRM10.ClothWarp.Components gravityDir = joint.m_gravityDir, gravityPower = joint.m_gravityPower, // mod - stiffnessForce = joint.m_stiffnessForce * 6, + stiffnessForce = joint.m_stiffnessForce /* * 6*/, }; if (i == 0) { @@ -97,14 +95,10 @@ namespace UniVRM10.ClothWarp.Components warp.SetSettings(joint.transform, settings); } } - // Undo.DestroyObjectImmediate(joint); - deleteObject(joint); } - spring.Joints.Clear(); warp.ColliderGroups = spring.ColliderGroups.ToList(); } } - instance.SpringBone.Springs.Clear(); } } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs index b05e25ce3..23fc6ded3 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs @@ -12,6 +12,9 @@ using UniVRM10; namespace UniVRM10.ClothWarp.Jobs { + /// + /// Job 版 + /// public class ClothWarpJobRuntime : IVrm10SpringBoneRuntime { Vrm10Instance _vrm; @@ -129,7 +132,7 @@ namespace UniVRM10.ClothWarp.Jobs _currentColliders = new(_colliderTransforms.Count, Allocator.Persistent); // - // warps + // warps => particles // _transforms = new(); List info = new(); @@ -334,6 +337,13 @@ namespace UniVRM10.ClothWarp.Jobs }.Schedule(_info.Length, 128, handle); } + // 親子の長さで拘束. TODO: ApplyRotationJob と合体 + handle = new ParentLengthConstraintJob + { + Warps = _warps, + Info = _info, + NextPositions = _nextPositions, + }.Schedule(_warps.Length, 16, handle); // NextPositions から NextRotations を作る handle = new ApplyRotationJob { diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Particle.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Particle.cs index c85550f8a..4836935a5 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Particle.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Particle.cs @@ -77,6 +77,7 @@ namespace UniVRM10.ClothWarp.Jobs public void Execute(int particleIndex) { + const float FACTOR = 6.0f; var particle = Info[particleIndex]; if (particle.TransformType.Movable()) { @@ -85,13 +86,15 @@ namespace UniVRM10.ClothWarp.Jobs var parent = Info[parentIndex]; var parentParentRotation = CurrentTransforms[parent.ParentIndex].Rotation; - var external = (particle.Settings.gravityDir * particle.Settings.gravityPower + Frame.Force) * Frame.DeltaTime; + var velocity = (CurrentPositions[particleIndex] - PrevPositions[particleIndex]) * (1.0f - particle.Settings.dragForce); + var resilience = parentParentRotation * parent.InitLocalRotation * particle.InitLocalPosition * + particle.Settings.stiffnessForce * FACTOR; // 親の回転による子ボーンの移動目標 + var external = particle.Settings.gravityDir * particle.Settings.gravityPower + Frame.Force; var newPosition = CurrentPositions[particleIndex] - + (CurrentPositions[particleIndex] - PrevPositions[particleIndex]) * (1.0f - particle.Settings.dragForce) - + parentParentRotation * parent.InitLocalRotation * particle.InitLocalPosition * - particle.Settings.stiffnessForce * Frame.DeltaTime // 親の回転による子ボーンの移動目標 - + external + + velocity + + resilience * Frame.DeltaTime + + external * Frame.DeltaTime ; NextPositions[particleIndex] = newPosition; From 9f1977d76f3d5fd75e9fcf4b7a6e294997d982d3 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 14:21:06 +0900 Subject: [PATCH 07/25] fix factor. add cloth to hips --- .../ClothSample/ClothViewer/ClothViewer.unity | 320 +++++++++++++++++- .../ClothSample/ClothViewer/ClothViewerUI.cs | 17 +- .../Components/ClothWarpRuntimeProvider.cs | 7 +- .../Runtime/Jobs/ClothWarpJobRuntime.cs | 6 +- .../ClothWarp/Runtime/Jobs/Particle.cs | 3 +- 5 files changed, 339 insertions(+), 14 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.unity b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.unity index 75d5db057..d6abc2f6b 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.unity +++ b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.unity @@ -402,7 +402,7 @@ MonoBehaviour: onValueChanged: m_PersistentCalls: m_Calls: [] - m_IsOn: 0 + m_IsOn: 1 --- !u!1 &153452228 GameObject: m_ObjectHideFlags: 0 @@ -686,6 +686,92 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 168425994} m_CullTransparentMesh: 0 +--- !u!1 &172483632 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 172483633} + - component: {fileID: 172483634} + m_Layer: 5 + m_Name: AddClothToHips + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &172483633 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 172483632} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1472853923} + - {fileID: 1724807119} + m_Father: {fileID: 339774397} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 162, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &172483634 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 172483632} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Highlighted + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1472853924} + toggleTransition: 1 + graphic: {fileID: 1236232219} + m_Group: {fileID: 0} + onValueChanged: + m_PersistentCalls: + m_Calls: [] + m_IsOn: 1 --- !u!1 &175751362 GameObject: m_ObjectHideFlags: 0 @@ -1407,6 +1493,7 @@ RectTransform: - {fileID: 1767706907} - {fileID: 947409974} - {fileID: 135168672} + - {fileID: 172483633} - {fileID: 2144476967} - {fileID: 1194499280} - {fileID: 153452229} @@ -5027,6 +5114,81 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1215781541} m_CullTransparentMesh: 0 +--- !u!1 &1236232217 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1236232218} + - component: {fileID: 1236232220} + - component: {fileID: 1236232219} + m_Layer: 5 + m_Name: Checkmark + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1236232218 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1236232217} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1472853923} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 20, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1236232219 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1236232217} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1236232220 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1236232217} + m_CullTransparentMesh: 0 --- !u!1 &1242458542 GameObject: m_ObjectHideFlags: 0 @@ -6228,6 +6390,82 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] m_IsOn: 0 +--- !u!1 &1472853922 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1472853923} + - component: {fileID: 1472853925} + - component: {fileID: 1472853924} + m_Layer: 5 + m_Name: Background + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1472853923 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1472853922} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1236232218} + m_Father: {fileID: 172483633} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 10, y: -10} + m_SizeDelta: {x: 20, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1472853924 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1472853922} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1472853925 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1472853922} + m_CullTransparentMesh: 0 --- !u!1 &1476033060 GameObject: m_ObjectHideFlags: 0 @@ -6774,6 +7012,85 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1684483641} m_CullTransparentMesh: 0 +--- !u!1 &1724807118 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1724807119} + - component: {fileID: 1724807121} + - component: {fileID: 1724807120} + m_Layer: 5 + m_Name: Label + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1724807119 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1724807118} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 172483633} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 9, y: -0.5} + m_SizeDelta: {x: -28, y: -3} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1724807120 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1724807118} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Add cloth to Hips +--- !u!222 &1724807121 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1724807118} + m_CullTransparentMesh: 0 --- !u!1 &1761414315 GameObject: m_ObjectHideFlags: 0 @@ -7224,6 +7541,7 @@ MonoBehaviour: m_openModel: {fileID: 2009818433} m_showBoxMan: {fileID: 1767706908} m_useJob: {fileID: 135168673} + m_addClothToHips: {fileID: 172483634} m_reconstructSprngBone: {fileID: 2144476968} m_resetSpringBone: {fileID: 1194499281} m_pauseSpringBone: {fileID: 153452230} diff --git a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs index 7edcdfcca..a25670807 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewerUI.cs @@ -21,6 +21,7 @@ namespace UniVRM10.Cloth.Viewer [Header("Cloth")] [SerializeField] Toggle m_useJob = default; + [SerializeField] Toggle m_addClothToHips = default; [SerializeField] Button m_reconstructSprngBone = default; [SerializeField] Button m_resetSpringBone = default; [SerializeField] Toggle m_pauseSpringBone = default; @@ -61,6 +62,7 @@ namespace UniVRM10.Cloth.Viewer m_showBoxMan = map.Get("ShowBoxMan"); m_useJob = map.Get("UseJob"); + m_addClothToHips = map.Get("AddClothToHips"); m_reconstructSprngBone = map.Get