mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-31 23:12:52 -05:00
ParticleSettings
This commit is contained in:
parent
3d07d160ce
commit
4c6f5ebb48
|
|
@ -138,7 +138,7 @@ namespace UniVRM10.Cloth.Viewer
|
|||
var warp = childchild.gameObject.AddComponent<ClothWarpRoot>();
|
||||
// Name = name,
|
||||
// CollisionMask = mask,
|
||||
warp.BaseSettings.radius = 0.02f;
|
||||
warp.BaseSettings.Radius = 0.02f;
|
||||
// Connection = type
|
||||
transforms.Add(warp);
|
||||
break;
|
||||
|
|
@ -179,7 +179,7 @@ namespace UniVRM10.Cloth.Viewer
|
|||
if (warp != null)
|
||||
{
|
||||
// CollisionMask = mask,
|
||||
warp.BaseSettings.radius = 0.02f;
|
||||
warp.BaseSettings.Radius = 0.02f;
|
||||
// Connection = type
|
||||
transforms.Add(warp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,11 +95,10 @@ namespace UniVRM10.ClothWarp.Components
|
|||
m_treeview = new MultiColumnTreeView();
|
||||
BindColumn("Transform", 120, () => new ObjectField(), (_) => false, "Transform");
|
||||
BindColumn("Mode", 40, () => new EnumField(), (_) => true, "Mode");
|
||||
BindColumn("stiffnessForce", 40, () => new FloatField(), isCustom, "Settings.stiffnessForce");
|
||||
BindColumn("gravityPower", 40, () => new FloatField(), isCustom, "Settings.gravityPower");
|
||||
BindColumn("gravityDir", 120, () => new Vector3Field(), isCustom, "Settings.gravityDir");
|
||||
BindColumn("dragForce", 40, () => new FloatField(), isCustom, "Settings.dragForce");
|
||||
BindColumn("radius", 40, () => new FloatField(), isCustom, "Settings.radius");
|
||||
BindColumn("Stiffness", 40, () => new FloatField(), isCustom, "Settings.Stiffness");
|
||||
BindColumn("Gravity", 120, () => new Vector3Field(), isCustom, "Settings.Gravity");
|
||||
BindColumn("Deceleration", 40, () => new FloatField(), isCustom, "Settings.Deceleration");
|
||||
BindColumn("Radius", 40, () => new FloatField(), isCustom, "Settings.Radius");
|
||||
|
||||
m_treeview.autoExpand = true;
|
||||
m_treeview.SetRootItems(m_target.m_rootitems);
|
||||
|
|
@ -117,10 +116,10 @@ namespace UniVRM10.ClothWarp.Components
|
|||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
m_vrm.Runtime.SpringBone.SetJointLevel(m_target.transform, m_target.BaseSettings);
|
||||
m_vrm.Runtime.SpringBone.SetJointLevel(m_target.transform, m_target.BaseSettings.ToBlittableJointMutable());
|
||||
foreach (var p in m_target.Particles)
|
||||
{
|
||||
m_vrm.Runtime.SpringBone.SetJointLevel(p.Transform, p.Settings);
|
||||
m_vrm.Runtime.SpringBone.SetJointLevel(p.Transform, p.Settings.ToBlittableJointMutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -153,7 +152,7 @@ namespace UniVRM10.ClothWarp.Components
|
|||
p = m_target.GetParticleFromTransform(p.Transform);
|
||||
var t = p.Transform;
|
||||
Handles.color = Color.green;
|
||||
Handles.SphereHandleCap(t.GetInstanceID(), t.position, t.rotation, p.Settings.radius * 2, EventType.Repaint);
|
||||
Handles.SphereHandleCap(t.GetInstanceID(), t.position, t.rotation, p.Settings.Radius * 2, EventType.Repaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UniGLTF.SpringBoneJobs.Blittables;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
|
@ -17,18 +16,6 @@ namespace UniVRM10.ClothWarp.Components
|
|||
/// </summary>
|
||||
public class ClothWarpRoot : MonoBehaviour
|
||||
{
|
||||
public static BlittableJointMutable DefaultSetting()
|
||||
{
|
||||
return new BlittableJointMutable
|
||||
{
|
||||
stiffnessForce = 1.0f,
|
||||
gravityPower = 0,
|
||||
gravityDir = new Vector3(0, -1.0f, 0),
|
||||
dragForce = 0.4f,
|
||||
radius = 0.02f,
|
||||
};
|
||||
}
|
||||
|
||||
public enum ParticleMode
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -53,28 +40,28 @@ namespace UniVRM10.ClothWarp.Components
|
|||
{
|
||||
public Transform Transform;
|
||||
public ParticleMode Mode;
|
||||
public BlittableJointMutable Settings;
|
||||
public Jobs.ParticleSettings Settings;
|
||||
|
||||
public Particle(Transform t, ParticleMode mode, BlittableJointMutable settings)
|
||||
public Particle(Transform t, ParticleMode mode, Jobs.ParticleSettings settings)
|
||||
{
|
||||
Transform = t;
|
||||
Mode = mode;
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
public Particle(Transform t, BlittableJointMutable settings)
|
||||
public Particle(Transform t, Jobs.ParticleSettings settings)
|
||||
: this(t, ParticleMode.Custom, settings)
|
||||
{
|
||||
}
|
||||
|
||||
public Particle(Transform t)
|
||||
: this(t, ParticleMode.Base, DefaultSetting())
|
||||
: this(t, ParticleMode.Base, Jobs.ParticleSettings.Default)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
public BlittableJointMutable BaseSettings = DefaultSetting();
|
||||
public Jobs.ParticleSettings BaseSettings = Jobs.ParticleSettings.Default;
|
||||
|
||||
/// <summary>
|
||||
/// null のときは world root ではなく model root で処理
|
||||
|
|
@ -214,7 +201,7 @@ namespace UniVRM10.ClothWarp.Components
|
|||
}
|
||||
}
|
||||
|
||||
public void SetSettings(Transform t, BlittableJointMutable settings)
|
||||
public void SetSettings(Transform t, Jobs.ParticleSettings settings)
|
||||
{
|
||||
if (t == null) return;
|
||||
for (int i = 0; i < m_particles.Count; ++i)
|
||||
|
|
@ -232,7 +219,7 @@ namespace UniVRM10.ClothWarp.Components
|
|||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.DrawSphere(transform.position, BaseSettings.radius);
|
||||
Gizmos.DrawSphere(transform.position, BaseSettings.Radius);
|
||||
|
||||
foreach (var p in Particles)
|
||||
{
|
||||
|
|
@ -240,7 +227,7 @@ namespace UniVRM10.ClothWarp.Components
|
|||
{
|
||||
continue;
|
||||
}
|
||||
Gizmos.DrawWireSphere(p.Transform.position, p.Settings.radius);
|
||||
Gizmos.DrawWireSphere(p.Transform.position, p.Settings.Radius);
|
||||
|
||||
if (TryGetClosestParent(p.Transform, out var parent))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -70,24 +70,23 @@ namespace UniVRM10.ClothWarp.Components
|
|||
var joint = joints[i];
|
||||
|
||||
// mod ?
|
||||
var stiffness = joint.m_stiffnessForce;
|
||||
var stiffness = Mathf.Min(0.08f, joint.m_stiffnessForce * 0.1f);
|
||||
|
||||
var settings = new UniGLTF.SpringBoneJobs.Blittables.BlittableJointMutable
|
||||
var settings = new Jobs.ParticleSettings
|
||||
{
|
||||
dragForce = joint.m_dragForce,
|
||||
gravityDir = joint.m_gravityDir,
|
||||
gravityPower = joint.m_gravityPower,
|
||||
stiffnessForce = stiffness,
|
||||
Deceleration = joint.m_dragForce,
|
||||
Gravity = joint.m_gravityDir * joint.m_gravityPower,
|
||||
Stiffness = stiffness,
|
||||
};
|
||||
if (i == 0)
|
||||
{
|
||||
settings.radius = joints[0].m_jointRadius;
|
||||
settings.Radius = joints[0].m_jointRadius;
|
||||
warp.BaseSettings = settings;
|
||||
}
|
||||
else
|
||||
{
|
||||
// breaking change from vrm-1.0
|
||||
settings.radius = joints[i - 1].m_jointRadius;
|
||||
settings.Radius = joints[i - 1].m_jointRadius;
|
||||
var useInheritSettings = warp.BaseSettings.Equals(settings);
|
||||
if (useInheritSettings)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -549,11 +549,11 @@ namespace UniVRM10.ClothWarp.Jobs
|
|||
break;
|
||||
case TransformType.ClothWarp:
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawSphere(v, info.Settings.radius);
|
||||
Gizmos.DrawSphere(v, info.Settings.Radius);
|
||||
break;
|
||||
case TransformType.Particle:
|
||||
Gizmos.color = Color.cyan;
|
||||
Gizmos.DrawWireSphere(v, info.Settings.radius);
|
||||
Gizmos.DrawWireSphere(v, info.Settings.Radius);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -565,7 +565,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
|||
if (i != -1)
|
||||
{
|
||||
var info = _info[i];
|
||||
info.Settings = jointSettings;
|
||||
info.Settings.FromBlittableJointMutable(jointSettings);
|
||||
_info[i] = info;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using UniGLTF.SpringBoneJobs.Blittables;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
|
@ -7,13 +8,56 @@ using UnityEngine.Jobs;
|
|||
|
||||
namespace UniVRM10.ClothWarp.Jobs
|
||||
{
|
||||
/// <summary>
|
||||
/// UniGLTF.SpringBoneJobs.Blittables.BlittableJointMutable と同じ。
|
||||
/// Range が違う。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct ParticleSettings
|
||||
{
|
||||
[Range(0, 1)]
|
||||
public float Stiffness;
|
||||
[Range(0, 1)]
|
||||
public float Deceleration;
|
||||
public Vector3 Gravity;
|
||||
public float Radius;
|
||||
|
||||
public static readonly ParticleSettings Default = new ParticleSettings
|
||||
{
|
||||
Stiffness = 0.08f,
|
||||
Gravity = new Vector3(0, -1.0f, 0),
|
||||
Deceleration = 0.4f,
|
||||
Radius = 0.02f,
|
||||
};
|
||||
|
||||
public void FromBlittableJointMutable(BlittableJointMutable src)
|
||||
{
|
||||
Stiffness = src.stiffnessForce;
|
||||
Gravity = src.gravityDir * src.gravityPower;
|
||||
Deceleration = src.dragForce;
|
||||
Radius = src.radius;
|
||||
}
|
||||
|
||||
public BlittableJointMutable ToBlittableJointMutable()
|
||||
{
|
||||
return new BlittableJointMutable
|
||||
{
|
||||
stiffnessForce = Stiffness,
|
||||
gravityPower = 1.0f,
|
||||
gravityDir = Gravity,
|
||||
dragForce = Deceleration,
|
||||
radius = Radius,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public struct TransformInfo
|
||||
{
|
||||
public TransformType TransformType;
|
||||
public int ParentIndex;
|
||||
public Quaternion InitLocalRotation;
|
||||
public Vector3 InitLocalPosition;
|
||||
public BlittableJointMutable Settings;
|
||||
public ParticleSettings Settings;
|
||||
public int WarpIndex;
|
||||
}
|
||||
|
||||
|
|
@ -87,16 +131,13 @@ namespace UniVRM10.ClothWarp.Jobs
|
|||
var local_rest = parentParentRotation * parent.InitLocalRotation * particle.InitLocalPosition;
|
||||
var world_rest = CurrentPositions[particle.ParentIndex] + local_rest;
|
||||
var resilience_force = world_rest - CurrentPositions[particleIndex];
|
||||
var velocity = (CurrentPositions[particleIndex] - PrevPositions[particleIndex]) * (1.0f - particle.Settings.dragForce);
|
||||
var resilience = parentParentRotation * parent.InitLocalRotation * particle.InitLocalPosition.normalized *
|
||||
particle.Settings.stiffnessForce;
|
||||
var external = particle.Settings.gravityDir * particle.Settings.gravityPower + Frame.Force;
|
||||
var velocity = (CurrentPositions[particleIndex] - PrevPositions[particleIndex]) * (1.0f - particle.Settings.Deceleration);
|
||||
|
||||
var newPosition = CurrentPositions[particleIndex]
|
||||
+ velocity
|
||||
+ ImpulsiveForces[particleIndex]
|
||||
+ resilience * Frame.DeltaTime
|
||||
+ external * Frame.DeltaTime
|
||||
+ resilience_force * particle.Settings.Stiffness
|
||||
+ (particle.Settings.Gravity + Frame.Force) * Frame.SqDeltaTime
|
||||
;
|
||||
|
||||
NextPositions[particleIndex] = newPosition;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
|||
if (c.colliderType == BlittableColliderType.Capsule)
|
||||
{
|
||||
if (SphereSphereCollision.TryCollideCapsuleAndSphere(m.MultiplyPoint(c.offset), m.MultiplyPoint(c.tailOrNormal), c.radius,
|
||||
pos, info.Settings.radius, out var l))
|
||||
pos, info.Settings.Radius, out var l))
|
||||
{
|
||||
pos += l.GetDelta(c.radius);
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
|||
else
|
||||
{
|
||||
if (SphereSphereCollision.TryCollideSphereAndSphere(m.MultiplyPoint(c.offset), c.radius,
|
||||
pos, info.Settings.radius, out var l))
|
||||
pos, info.Settings.Radius, out var l))
|
||||
{
|
||||
pos += l.GetDelta(c.radius);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace UniVRM10.ClothWarp
|
|||
foreach (var particle in warp.Particles)
|
||||
{
|
||||
var child_index = _MakeAParticle(joint, env, particle.Transform,
|
||||
particle.Settings.radius, 1);
|
||||
particle.Settings.Radius, 1);
|
||||
var child = _particles[child_index];
|
||||
strand.Particles.Add(child);
|
||||
joint.Children.Add(child);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user