mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-22 10:34:54 -05:00
Merge pull request #877 from ousttrue/feature10/VRM10SpringBone_is_monobehaviour
VRM10SpringBone を MonoBehaviour にした
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using VrmLib;
|
||||
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
@@ -57,7 +57,6 @@ namespace UniVRM10
|
||||
m_expression = PropGui.FromObject(serializedObject, nameof(m_target.Expression));
|
||||
m_lookAt = PropGui.FromObject(serializedObject, nameof(m_target.LookAt));
|
||||
m_firstPerson = PropGui.FromObject(serializedObject, nameof(m_target.FirstPerson));
|
||||
m_springBone = PropGui.FromObject(serializedObject, nameof(m_target.SpringBone));
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
@@ -76,7 +75,6 @@ namespace UniVRM10
|
||||
Expression,
|
||||
LookAt,
|
||||
FirstPerson,
|
||||
SpringBone,
|
||||
}
|
||||
Tabs _tab;
|
||||
|
||||
@@ -118,7 +116,6 @@ namespace UniVRM10
|
||||
PropGui m_expression;
|
||||
PropGui m_lookAt;
|
||||
PropGui m_firstPerson;
|
||||
PropGui m_springBone;
|
||||
PropGui m_asset;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@@ -161,10 +158,6 @@ namespace UniVRM10
|
||||
case Tabs.FirstPerson:
|
||||
m_firstPerson.RecursiveProperty();
|
||||
break;
|
||||
|
||||
case Tabs.SpringBone:
|
||||
m_springBone.RecursiveProperty();
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
@@ -8,9 +8,16 @@ namespace UniVRM10
|
||||
/// <summary>
|
||||
/// The base algorithm is http://rocketjump.skr.jp/unity3d/109/ of @ricopin416
|
||||
/// DefaultExecutionOrder(11000) means calculate springbone after FinalIK( VRIK )
|
||||
///
|
||||
/// Setup の Editor の都合から、VRM10SpringBone は MonoBehaviour にする。
|
||||
/// Data置き場。Updateは使わない。
|
||||
///
|
||||
/// Springの根元のTranform (Joints.First()) に AddComponent して使う。
|
||||
///
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[Serializable]
|
||||
public class VRM10SpringBone
|
||||
public class VRM10SpringBone : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public string Comment;
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace UniVRM10
|
||||
/// <summary>
|
||||
/// VRMC_node_collider
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("VRM10/VRM10SpringBoneColliderGroup")]
|
||||
public class VRM10SpringBoneColliderGroup : MonoBehaviour
|
||||
{
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
/// <summary>
|
||||
/// すべての SpringBone を管理する。
|
||||
/// Humanoid 一体につきひとつだけ存在する。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class VRM10SpringBoneManager
|
||||
{
|
||||
[SerializeField, Header("Gizmo")]
|
||||
bool m_drawGizmo = default;
|
||||
|
||||
[SerializeField]
|
||||
Color m_gizmoColor = Color.yellow;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
public List<VRM10SpringBone> Springs = new List<VRM10SpringBone>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 1フレームに一回呼び出す(VRM10Controllerの仕事)
|
||||
/// </summary>
|
||||
public void Process()
|
||||
{
|
||||
foreach (var spring in Springs)
|
||||
{
|
||||
spring.Process();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawGizmos()
|
||||
{
|
||||
if (m_drawGizmo)
|
||||
{
|
||||
foreach (var spring in Springs)
|
||||
{
|
||||
spring.DrawGizmo(m_gizmoColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d09e28f7198c42d42bb31fd40e164b2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -44,9 +44,6 @@ namespace UniVRM10
|
||||
[SerializeField]
|
||||
public VRM10ControllerFirstPerson FirstPerson = new VRM10ControllerFirstPerson();
|
||||
|
||||
[SerializeField]
|
||||
public VRM10SpringBoneManager SpringBone = new VRM10SpringBoneManager();
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (Expression != null)
|
||||
@@ -55,6 +52,8 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
VRM10SpringBone[] m_springs;
|
||||
|
||||
VRM10Constraint[] m_constraints;
|
||||
|
||||
Transform m_head;
|
||||
@@ -123,7 +122,14 @@ namespace UniVRM10
|
||||
//
|
||||
// spring
|
||||
//
|
||||
SpringBone.Process();
|
||||
if (m_springs == null)
|
||||
{
|
||||
m_springs = GetComponentsInChildren<VRM10SpringBone>();
|
||||
}
|
||||
foreach (var spring in m_springs)
|
||||
{
|
||||
spring.Process();
|
||||
}
|
||||
|
||||
//
|
||||
// gaze control
|
||||
@@ -156,10 +162,5 @@ namespace UniVRM10
|
||||
Process();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
SpringBone.DrawGizmos();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,14 +346,17 @@ namespace UniVRM10
|
||||
{
|
||||
await awaitCaller.NextFrame();
|
||||
|
||||
var springBoneManager = controller.SpringBone;
|
||||
|
||||
// springs
|
||||
if (gltfVrmSpringBone.Springs != null)
|
||||
{
|
||||
foreach (var gltfSpring in gltfVrmSpringBone.Springs)
|
||||
{
|
||||
var springBone = new VRM10SpringBone();
|
||||
if (gltfSpring.Joints == null || gltfSpring.Joints.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var firstJointNode = Nodes[gltfSpring.Joints.First().Node.Value];
|
||||
var springBone = firstJointNode.gameObject.AddComponent<VRM10SpringBone>();
|
||||
springBone.Comment = gltfSpring.Name;
|
||||
|
||||
// joint
|
||||
@@ -422,8 +425,6 @@ namespace UniVRM10
|
||||
return null;
|
||||
}
|
||||
}).Where(x => x != null));
|
||||
|
||||
springBoneManager.Springs.Add(springBone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,11 +295,6 @@ namespace UniVRM10
|
||||
|
||||
UniGLTF.Extensions.VRMC_springBone.VRMC_springBone ExportSpringBone(VRM10Controller vrmController, Model model, RuntimeVrmConverter converter)
|
||||
{
|
||||
if (vrmController?.SpringBone?.Springs == null || vrmController.SpringBone.Springs.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var springBone = new UniGLTF.Extensions.VRMC_springBone.VRMC_springBone
|
||||
{
|
||||
Springs = new List<UniGLTF.Extensions.VRMC_springBone.Spring>(),
|
||||
@@ -311,7 +306,7 @@ namespace UniVRM10
|
||||
return model.Nodes.IndexOf(node);
|
||||
};
|
||||
|
||||
foreach (var x in vrmController.SpringBone.Springs)
|
||||
foreach (var x in vrmController.GetComponentsInChildren<VRM10SpringBone>())
|
||||
{
|
||||
var spring = new UniGLTF.Extensions.VRMC_springBone.Spring
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user