mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-26 12:50:40 -05:00
Converter.FromVrm10
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UniVRM10;
|
||||
@@ -20,12 +21,21 @@ namespace RotateParticle.Components
|
||||
return go.GetComponent<Vrm10Instance>() != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// instance.SpringBone.Springs を rotate particle で置き換える。
|
||||
/// UNDO 可能。
|
||||
/// </summary>
|
||||
[MenuItem(FROM_VRM10_MENU, false)]
|
||||
public static void FromVrm10()
|
||||
{
|
||||
var go = Selection.activeGameObject;
|
||||
var instance = go.GetComponent<Vrm10Instance>();
|
||||
|
||||
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<Warp>() != null)
|
||||
if (root_joint.GetComponent<Warp>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
UnityEditor.Undo.IncrementCurrentGroup();
|
||||
UnityEditor.Undo.SetCurrentGroupName("VRM10SpringBoneColliderGroup.Separate");
|
||||
var warp = Undo.AddComponent<Warp>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -25,29 +39,29 @@ namespace RotateParticle.Components
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
ParticleSettings BaseSettings;
|
||||
public ParticleSettings BaseSettings;
|
||||
|
||||
/// <summary>
|
||||
/// null のときは world root ではなく model root で処理
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
Transform Center;
|
||||
public Transform Center;
|
||||
|
||||
/// <summary>
|
||||
/// 枝分かれ不可
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
List<Particle> Particles = new List<Particle>();
|
||||
public List<Particle> Particles = new List<Particle>();
|
||||
|
||||
void Reset()
|
||||
{
|
||||
Debug.Log("Warp.Reset");
|
||||
// Debug.Log("Warp.Reset");
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
// 枝分かれを削除
|
||||
Debug.Log("Warp.OnValidate");
|
||||
// TODO: 枝分かれを削除
|
||||
// Debug.Log("Warp.OnValidate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user