mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-25 03:55:52 -05:00
Merge pull request #1498 from 0b5vr/constraint-axes
[1.0] Constraint, freezeAxes -> axes
This commit is contained in:
@@ -96,9 +96,9 @@ namespace UniVRM10
|
||||
// show dst
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine(m_target.FreezeAxes.HasFlag(AxisMask.X) ? $"freeze" : $"{delta.x:0.00}");
|
||||
sb.AppendLine(m_target.FreezeAxes.HasFlag(AxisMask.Y) ? $"freeze" : $"{delta.y:0.00}");
|
||||
sb.Append(m_target.FreezeAxes.HasFlag(AxisMask.Z) ? $"freeze" : $"{delta.z:0.00}");
|
||||
sb.AppendLine(m_target.Axes.HasFlag(AxisMask.X) ? $"{delta.x:0.00}" : "----");
|
||||
sb.AppendLine(m_target.Axes.HasFlag(AxisMask.Y) ? $"{delta.y:0.00}" : "----");
|
||||
sb.Append(m_target.Axes.HasFlag(AxisMask.Z) ? $"{delta.z:0.00}" : "----");
|
||||
Handles.Label(m_target.GetComponent().transform.position, sb.ToString(), Style);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
namespace UniVRM10
|
||||
{
|
||||
/// <summary>
|
||||
/// FreezeAxesで使う。bitマスク
|
||||
/// Axesで使う。bitマスク
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum AxisMask
|
||||
@@ -23,17 +23,17 @@ namespace UniVRM10
|
||||
|
||||
public static class AxesMaskExtensions
|
||||
{
|
||||
public static Vector3 Freeze(this AxisMask mask, Vector3 src)
|
||||
public static Vector3 Mask(this AxisMask mask, Vector3 src)
|
||||
{
|
||||
if (mask.HasFlag(AxisMask.X))
|
||||
if (!mask.HasFlag(AxisMask.X))
|
||||
{
|
||||
src.x = 0;
|
||||
}
|
||||
if (mask.HasFlag(AxisMask.Y))
|
||||
if (!mask.HasFlag(AxisMask.Y))
|
||||
{
|
||||
src.y = 0;
|
||||
}
|
||||
if (mask.HasFlag(AxisMask.Z))
|
||||
if (!mask.HasFlag(AxisMask.Z))
|
||||
{
|
||||
src.z = 0;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace UniVRM10
|
||||
[DisallowMultipleComponent]
|
||||
public class VRM10RotationConstraint : VRM10RotationPositionConstraintBase
|
||||
{
|
||||
public override Vector3 Delta => FreezeAxes.Freeze(Quaternion.Slerp(Quaternion.identity, m_delta.Rotation, Weight).eulerAngles);
|
||||
public override Vector3 Delta => Axes.Mask(Quaternion.Slerp(Quaternion.identity, m_delta.Rotation, Weight).eulerAngles);
|
||||
|
||||
public override TR GetSourceCurrent()
|
||||
{
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace UniVRM10
|
||||
{
|
||||
[SerializeField]
|
||||
[EnumFlags]
|
||||
AxisMask m_freezeAxes = default;
|
||||
public AxisMask FreezeAxes
|
||||
AxisMask m_axes = AxisMask.X | AxisMask.Y | AxisMask.Z;
|
||||
public AxisMask Axes
|
||||
{
|
||||
get => m_freezeAxes;
|
||||
set => m_freezeAxes = value;
|
||||
get => m_axes;
|
||||
set => m_axes = value;
|
||||
}
|
||||
|
||||
#region Source
|
||||
|
||||
@@ -116,8 +116,8 @@ public static RotationConstraint __constraint_Deserialize_Rotation(JsonNode pars
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="freezeAxes"){
|
||||
value.FreezeAxes = __constraint__rotation_Deserialize_FreezeAxes(kv.Value);
|
||||
if(key=="axes"){
|
||||
value.Axes = __constraint__rotation_Deserialize_Axes(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public static RotationConstraint __constraint_Deserialize_Rotation(JsonNode pars
|
||||
return value;
|
||||
}
|
||||
|
||||
public static bool[] __constraint__rotation_Deserialize_FreezeAxes(JsonNode parsed)
|
||||
public static bool[] __constraint__rotation_Deserialize_Axes(JsonNode parsed)
|
||||
{
|
||||
var value = new bool[parsed.GetArrayCount()];
|
||||
int i=0;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace UniGLTF.Extensions.VRMC_node_constraint
|
||||
public int? Source;
|
||||
|
||||
// Axes be constrained by this constraint, in X-Y-Z order.
|
||||
public bool[] FreezeAxes;
|
||||
public bool[] Axes;
|
||||
|
||||
// The weight of the constraint.
|
||||
public float? Weight;
|
||||
|
||||
@@ -104,9 +104,9 @@ public static void __constraint_Serialize_Rotation(JsonFormatter f, RotationCons
|
||||
f.Value(value.Source.GetValueOrDefault());
|
||||
}
|
||||
|
||||
if(value.FreezeAxes!=null&&value.FreezeAxes.Count()>=3){
|
||||
f.Key("freezeAxes");
|
||||
__constraint__rotation_Serialize_FreezeAxes(f, value.FreezeAxes);
|
||||
if(value.Axes!=null&&value.Axes.Count()>=3){
|
||||
f.Key("axes");
|
||||
__constraint__rotation_Serialize_Axes(f, value.Axes);
|
||||
}
|
||||
|
||||
if(value.Weight.HasValue){
|
||||
@@ -117,7 +117,7 @@ public static void __constraint_Serialize_Rotation(JsonFormatter f, RotationCons
|
||||
f.EndMap();
|
||||
}
|
||||
|
||||
public static void __constraint__rotation_Serialize_FreezeAxes(JsonFormatter f, bool[] value)
|
||||
public static void __constraint__rotation_Serialize_Axes(JsonFormatter f, bool[] value)
|
||||
{
|
||||
f.BeginList();
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ namespace UniVRM10
|
||||
Rotation = new UniGLTF.Extensions.VRMC_node_constraint.RotationConstraint
|
||||
{
|
||||
Source = model.Nodes.IndexOf(converter.Nodes[c.Source.gameObject]),
|
||||
FreezeAxes = ToArray(c.FreezeAxes),
|
||||
Axes = ToArray(c.Axes),
|
||||
Weight = c.Weight,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -613,7 +613,7 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
static AxisMask FreezeAxis(bool[] flags)
|
||||
static AxisMask ConstraintAxes(bool[] flags)
|
||||
{
|
||||
var mask = default(AxisMask);
|
||||
if (flags != null && flags.Length == 3)
|
||||
@@ -651,7 +651,7 @@ namespace UniVRM10
|
||||
var r = constraint.Rotation;
|
||||
var rotationConstraint = node.gameObject.AddComponent<VRM10RotationConstraint>();
|
||||
rotationConstraint.Source = Nodes[r.Source.Value];
|
||||
rotationConstraint.FreezeAxes = FreezeAxis(r.FreezeAxes);
|
||||
rotationConstraint.Axes = ConstraintAxes(r.Axes);
|
||||
rotationConstraint.Weight = r.Weight.Value;
|
||||
rotationConstraint.ModelRoot = Root.transform;
|
||||
}
|
||||
|
||||
Submodule vrm-specification updated: 4b63473e79...084c4fd3a1
Reference in New Issue
Block a user