diff --git a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothGuess.cs b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothGuess.cs index c1e18ddeb..590c7029b 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothGuess.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothGuess.cs @@ -140,7 +140,7 @@ namespace UniVRM10.Cloth.Viewer var warp = childchild.gameObject.AddComponent(); // Name = name, // CollisionMask = mask, - warp.BaseSettings.HitRadius = 0.02f; + warp.BaseSettings.radius = 0.02f; warp.AddParticleRecursive(); // Connection = type transforms.Add(warp); @@ -182,7 +182,7 @@ namespace UniVRM10.Cloth.Viewer if (warp != null) { // CollisionMask = mask, - warp.BaseSettings.HitRadius = 0.02f; + warp.BaseSettings.radius = 0.02f; warp.AddParticleRecursive(); // Connection = type transforms.Add(warp); diff --git a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.asmdef b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.asmdef index 75b04563e..619093ce2 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.asmdef +++ b/Assets/VRM10_Samples/ClothSample/ClothViewer/ClothViewer.asmdef @@ -6,7 +6,8 @@ "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:1cd941934d098654fa21a13f28346412", "GUID:e47c917724578cc43b5506c17a27e9a0", - "GUID:308b348fb80d89d42a9620951b0f60db" + "GUID:308b348fb80d89d42a9620951b0f60db", + "GUID:3e5d614bc16b50d41bd94c8d7444ca46" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticle.Editor.asmdef b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticle.Editor.asmdef index c91fbf05f..cc7849630 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticle.Editor.asmdef +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticle.Editor.asmdef @@ -3,7 +3,8 @@ "rootNamespace": "", "references": [ "GUID:308b348fb80d89d42a9620951b0f60db", - "GUID:e47c917724578cc43b5506c17a27e9a0" + "GUID:e47c917724578cc43b5506c17a27e9a0", + "GUID:3e5d614bc16b50d41bd94c8d7444ca46" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs index b730f3bf8..06c722cc4 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs @@ -57,6 +57,11 @@ namespace RotateParticle.Components } } + if (GUILayout.Button("Reset")) + { + provider.Reset(); + } + base.OnInspectorGUI(); } } diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/WarpEditor.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/WarpEditor.cs new file mode 100644 index 000000000..5d5c60a6b --- /dev/null +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/WarpEditor.cs @@ -0,0 +1,43 @@ +using UnityEditor; +using UnityEngine; +using UniVRM10; + +namespace RotateParticle.Components +{ + [CustomEditor(typeof(Warp))] + class WarpEditor : Editor + { + private Warp m_target; + private Vrm10Instance m_vrm; + + void OnEnable() + { + if (target == null) + { + return; + } + m_target = (Warp)target; + 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)); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/WarpEditor.cs.meta b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/WarpEditor.cs.meta new file mode 100644 index 000000000..df08113d4 --- /dev/null +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/WarpEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea017d386e4fdee47b8a896571e2a0de +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs index 4acceea41..605713fd4 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs @@ -64,22 +64,22 @@ namespace RotateParticle.Components for (int i = 0; i < joints.Length; ++i) { var joint = joints[i]; - var settings = new Warp.ParticleSettings + var settings = new UniGLTF.SpringBoneJobs.Blittables.BlittableJointMutable { - DragForce = joint.m_dragForce, - GravityDir = joint.m_gravityDir, - GravityPower = joint.m_gravityPower, - Stiffness = joint.m_stiffnessForce, + dragForce = joint.m_dragForce, + gravityDir = joint.m_gravityDir, + gravityPower = joint.m_gravityPower, + stiffnessForce = joint.m_stiffnessForce, }; if (i == 0) { - settings.HitRadius = joints[0].m_jointRadius; + settings.radius = joints[0].m_jointRadius; warp.BaseSettings = settings; } else { // breaking change from vrm-1.0 - settings.HitRadius = joints[i - 1].m_jointRadius; + settings.radius = joints[i - 1].m_jointRadius; var useInheritSettings = warp.BaseSettings.Equals(settings); warp.Particles.Add(new Warp.Particle { diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs index 5a3d09599..609ca2bf2 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using UniGLTF.SpringBoneJobs.Blittables; using UnityEngine; using UniVRM10; @@ -10,31 +11,15 @@ namespace RotateParticle.Components [DisallowMultipleComponent] public class Warp : MonoBehaviour { - [Serializable] - public struct ParticleSettings + public static BlittableJointMutable DefaultSetting() { - [SerializeField] - public float Stiffness; - - [SerializeField] - public float GravityPower; - - [SerializeField] - public Vector3 GravityDir; - - [SerializeField, Range(0, 1)] - public float DragForce; - - [SerializeField] - public float HitRadius; - - public static ParticleSettings Default => new ParticleSettings + return new BlittableJointMutable { - Stiffness = 1.0f, - GravityPower = 0, - GravityDir = new Vector3(0, -1.0f, 0), - DragForce = 0.4f, - HitRadius = 0.02f, + stiffnessForce = 1.0f, + gravityPower = 0, + gravityDir = new Vector3(0, -1.0f, 0), + dragForce = 0.4f, + radius = 0.02f, }; } @@ -45,17 +30,17 @@ namespace RotateParticle.Components public class Particle { public bool useInheritSettings = true; - public ParticleSettings OverrideSettings = ParticleSettings.Default; + public BlittableJointMutable OverrideSettings = DefaultSetting(); public Transform Transform; - public ParticleSettings GetSettings(ParticleSettings baseSettings) + public BlittableJointMutable GetSettings(BlittableJointMutable baseSettings) { return useInheritSettings ? baseSettings : OverrideSettings; } } [SerializeField] - public ParticleSettings BaseSettings = ParticleSettings.Default; + public BlittableJointMutable BaseSettings = DefaultSetting(); /// /// null のときは world root ではなく model root で処理 @@ -110,14 +95,14 @@ namespace RotateParticle.Components public void OnDrawGizmosSelected() { - Gizmos.DrawSphere(transform.position, BaseSettings.HitRadius); + Gizmos.DrawSphere(transform.position, BaseSettings.radius); Transform prev = transform; foreach (var p in Particles) { if (p != null && p.Transform != null) { - Gizmos.DrawWireSphere(p.Transform.position, p.GetSettings(BaseSettings).HitRadius); + Gizmos.DrawWireSphere(p.Transform.position, p.GetSettings(BaseSettings).radius); if (prev != null) { diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/IRotateParticleSystem.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/IRotateParticleSystem.cs index 962b5e8e0..e3a9de42c 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/IRotateParticleSystem.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/IRotateParticleSystem.cs @@ -1,6 +1,8 @@ using System; using System.Threading.Tasks; using UniGLTF; +using UniGLTF.SpringBoneJobs.Blittables; +using UnityEngine; using UniVRM10; namespace RotateParticle @@ -11,5 +13,7 @@ namespace RotateParticle void Process(float deltaTime); void ResetInitialRotation(); void DrawGizmos(); + + void SetJointLevel(Transform joint, BlittableJointMutable jointSettings); } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs index bb509dabe..a312ee5c4 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using RotateParticle.Components; using UniGLTF; +using UniGLTF.SpringBoneJobs.Blittables; using Unity.Collections; using Unity.Jobs; using UnityEngine; @@ -55,7 +56,7 @@ namespace RotateParticle.Jobs public int ParentIndex; public Quaternion InitLocalRotation; public Vector3 InitLocalPosition; - public Warp.ParticleSettings Settings; + public BlittableJointMutable Settings; } public struct TransformData @@ -156,9 +157,9 @@ namespace RotateParticle.Jobs var parentParentRotation = CurrentTransforms[parent.ParentIndex].Rotation; var newPosition = CurrentPositions[index] - + (CurrentPositions[index] - PrevPositions[index]) * (1.0f - particle.Settings.DragForce) + + (CurrentPositions[index] - PrevPositions[index]) * (1.0f - particle.Settings.dragForce) + parentParentRotation * parent.InitLocalRotation * particle.InitLocalPosition * - particle.Settings.Stiffness * Frame.DeltaTime // 親の回転による子ボーンの移動目標 + particle.Settings.stiffnessForce * Frame.DeltaTime // 親の回転による子ボーンの移動目標 + Frame.Force * Frame.SqDeltaTime ; @@ -371,5 +372,16 @@ namespace RotateParticle.Jobs void IRotateParticleSystem.DrawGizmos() { } + + public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings) + { + var i = _transforms.IndexOf(joint); + if (i != -1) + { + var info = _info[i]; + info.Settings = jointSettings; + _info[i] = info; + } + } } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/ParticleList.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/ParticleList.cs index ca09d8c57..4b4e951e4 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/ParticleList.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/ParticleList.cs @@ -24,7 +24,7 @@ namespace RotateParticle foreach (var particle in warp.Particles) { var child_index = _MakeAParticle(joint, env, particle.Transform, - particle.GetSettings(warp.BaseSettings).HitRadius, 1); + particle.GetSettings(warp.BaseSettings).radius, 1); var child = _particles[child_index]; strand.Particles.Add(child); joint.Children.Add(child); diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntime.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntime.cs index 7385778fa..825760b8e 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntime.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntime.cs @@ -34,6 +34,12 @@ namespace RotateParticle { _building = true; _vrm = vrm; + + if (_system != null) + { + _system.Dispose(); + } + if (_onInit != null) { _onInit(vrm); @@ -58,6 +64,10 @@ namespace RotateParticle public bool ReconstructSpringBone() { + if (_vrm == null) + { + return false; + } if (_building) { return false; @@ -74,10 +84,13 @@ namespace RotateParticle public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings) { + if (_system == null) return; + _system.SetJointLevel(joint, jointSettings); } public void SetModelLevel(Transform modelRoot, BlittableModelLevel modelSettings) { + if (_system == null) return; } public void DrawGizmos() diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs index 0999150dc..2b1bcdc6b 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using RotateParticle.Components; using SphereTriangle; using UniGLTF; +using UniGLTF.SpringBoneJobs.Blittables; using UnityEngine; using UniVRM10; @@ -438,5 +439,10 @@ namespace RotateParticle _newPos.DrawGizmos(); } } + + public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings) + { + throw new NotImplementedException(); + } } } \ No newline at end of file