mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-26 12:50:40 -05:00
SetJointLevel
This commit is contained in:
@@ -140,7 +140,7 @@ namespace UniVRM10.Cloth.Viewer
|
||||
var warp = childchild.gameObject.AddComponent<Warp>();
|
||||
// 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);
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:1cd941934d098654fa21a13f28346412",
|
||||
"GUID:e47c917724578cc43b5506c17a27e9a0",
|
||||
"GUID:308b348fb80d89d42a9620951b0f60db"
|
||||
"GUID:308b348fb80d89d42a9620951b0f60db",
|
||||
"GUID:3e5d614bc16b50d41bd94c8d7444ca46"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:308b348fb80d89d42a9620951b0f60db",
|
||||
"GUID:e47c917724578cc43b5506c17a27e9a0"
|
||||
"GUID:e47c917724578cc43b5506c17a27e9a0",
|
||||
"GUID:3e5d614bc16b50d41bd94c8d7444ca46"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -57,6 +57,11 @@ namespace RotateParticle.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Reset"))
|
||||
{
|
||||
provider.Reset();
|
||||
}
|
||||
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Vrm10Instance>();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea017d386e4fdee47b8a896571e2a0de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user