mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-21 18:15:39 -05:00
SrcDrawCurrent, DstDrawCurrent
This commit is contained in:
@@ -16,32 +16,11 @@ namespace UniVRM10
|
||||
m_target = (VRM10RotationConstraint)target;
|
||||
}
|
||||
|
||||
void DrawSrcModel()
|
||||
{
|
||||
var model = m_target.ModelRoot;
|
||||
var src = m_target.Source;
|
||||
if (model == null)
|
||||
{
|
||||
Handles.Label(src.position, "ModelRoot required");
|
||||
return;
|
||||
}
|
||||
|
||||
const float size = 0.05f;
|
||||
Handles.color = Color.red;
|
||||
Handles.DrawLine(src.position, src.position + model.right * size);
|
||||
Handles.color = Color.green;
|
||||
Handles.DrawLine(src.position, src.position + model.up * size);
|
||||
Handles.color = Color.black;
|
||||
Handles.DrawLine(src.position, src.position + model.forward * size);
|
||||
}
|
||||
|
||||
void DrawSrcLocal()
|
||||
#region SRC
|
||||
void SrcDrawCurrent()
|
||||
{
|
||||
var s = m_target.transform.lossyScale.x;
|
||||
|
||||
// init
|
||||
Coords.Write(m_target.GetSourceLocalInit(), 0.2f / s);
|
||||
|
||||
// current
|
||||
Handles.matrix = m_target.Source.localToWorldMatrix;
|
||||
Handles.color = Color.yellow;
|
||||
@@ -49,12 +28,27 @@ namespace UniVRM10
|
||||
Handles.DrawWireCube(Vector3.zero, new Vector3(size, size, size));
|
||||
}
|
||||
|
||||
void DrawDstLocal()
|
||||
void SrcDrawModelCoords()
|
||||
{
|
||||
var s = m_target.transform.lossyScale.x;
|
||||
|
||||
// init
|
||||
Coords.Write(m_target.GetDstLocalInit(), 0.2f / s);
|
||||
// init
|
||||
Coords.Write(m_target.GetSourceModelCoords(), 0.2f / s);
|
||||
}
|
||||
|
||||
void SrcDrawLocalCoords()
|
||||
{
|
||||
var s = m_target.transform.lossyScale.x;
|
||||
|
||||
// init
|
||||
Coords.Write(m_target.GetSourceLocalCoords(), 0.2f / s);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dst
|
||||
void DstDrawCurrent()
|
||||
{
|
||||
var s = m_target.transform.lossyScale.x;
|
||||
|
||||
// current
|
||||
Handles.matrix = m_target.transform.localToWorldMatrix;
|
||||
@@ -63,6 +57,20 @@ namespace UniVRM10
|
||||
Handles.DrawWireCube(Vector3.zero, new Vector3(size, size, size));
|
||||
}
|
||||
|
||||
void DstDrawModelCoords()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DstDrawLocalCoords()
|
||||
{
|
||||
var s = m_target.transform.lossyScale.x;
|
||||
|
||||
// init
|
||||
Coords.Write(m_target.GetDstLocalInit(), 0.2f / s);
|
||||
}
|
||||
#endregion
|
||||
|
||||
static GUIStyle s_style;
|
||||
|
||||
/// <summary>
|
||||
@@ -126,29 +134,32 @@ namespace UniVRM10
|
||||
switch (m_target.SourceCoordinate)
|
||||
{
|
||||
case ObjectSpace.model:
|
||||
DrawSrcModel();
|
||||
SrcDrawModelCoords();
|
||||
break;
|
||||
|
||||
case ObjectSpace.local:
|
||||
DrawSrcLocal();
|
||||
SrcDrawLocalCoords();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
SrcDrawCurrent();
|
||||
|
||||
switch (m_target.DestinationCoordinate)
|
||||
{
|
||||
case ObjectSpace.model:
|
||||
DstDrawModelCoords();
|
||||
break;
|
||||
|
||||
case ObjectSpace.local:
|
||||
DrawDstLocal();
|
||||
DstDrawLocalCoords();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
DstDrawCurrent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,15 @@ namespace UniVRM10
|
||||
{
|
||||
public readonly Transform ModelRoot;
|
||||
readonly Transform m_transform;
|
||||
readonly TRS m_modelInitial;
|
||||
|
||||
/// <summary>
|
||||
/// initial: ModelRoot.localToWorldMatrix^-1 * t.localToWorldMatrix
|
||||
/// </summary>
|
||||
public readonly TRS ModelInitial;
|
||||
|
||||
/// <summary>
|
||||
/// initial: t.localPosition, t.localRotation, t.localScale
|
||||
/// </summary>
|
||||
public readonly TRS LocalInitial;
|
||||
|
||||
public Vector3 TranslationDelta(ObjectSpace coords)
|
||||
@@ -17,7 +25,7 @@ namespace UniVRM10
|
||||
{
|
||||
// case ObjectSpace.World: return m_transform.position - m_initial.Translation;
|
||||
case ObjectSpace.local: return m_transform.localPosition - LocalInitial.Translation;
|
||||
case ObjectSpace.model: return ModelRoot.worldToLocalMatrix.MultiplyPoint(m_transform.position) - m_modelInitial.Translation;
|
||||
case ObjectSpace.model: return ModelRoot.worldToLocalMatrix.MultiplyPoint(m_transform.position) - ModelInitial.Translation;
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +37,7 @@ namespace UniVRM10
|
||||
// 右からかけるか、左からかけるか、それが問題なのだ
|
||||
// case SourceCoordinates.World: return m_transform.rotation * Quaternion.Inverse(m_initial.Rotation);
|
||||
case ObjectSpace.local: return m_transform.localRotation * Quaternion.Inverse(LocalInitial.Rotation);
|
||||
case ObjectSpace.model: return m_transform.rotation * Quaternion.Inverse(ModelRoot.rotation) * Quaternion.Inverse(m_modelInitial.Rotation);
|
||||
case ObjectSpace.model: return m_transform.rotation * Quaternion.Inverse(ModelRoot.rotation) * Quaternion.Inverse(ModelInitial.Rotation);
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -45,7 +53,7 @@ namespace UniVRM10
|
||||
{
|
||||
var world = TRS.GetWorld(t);
|
||||
ModelRoot = modelRoot;
|
||||
m_modelInitial = new TRS
|
||||
ModelInitial = new TRS
|
||||
{
|
||||
Translation = modelRoot.worldToLocalMatrix.MultiplyPoint(world.Translation),
|
||||
Rotation = world.Rotation * Quaternion.Inverse(ModelRoot.rotation),
|
||||
|
||||
@@ -34,25 +34,49 @@ namespace UniVRM10
|
||||
public Transform ModelRoot = default;
|
||||
|
||||
ConstraintSource m_src;
|
||||
public Matrix4x4 GetSourceLocalInit()
|
||||
|
||||
/// <summary>
|
||||
/// Model の座標系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Matrix4x4 GetSourceModelCoords()
|
||||
{
|
||||
if (m_src != null)
|
||||
if (Source != null)
|
||||
{
|
||||
var parent = Matrix4x4.identity;
|
||||
if (Source != null && Source.parent != null)
|
||||
if (ModelRoot != null)
|
||||
{
|
||||
parent = Source.parent.localToWorldMatrix;
|
||||
return ModelRoot.localToWorldMatrix * Matrix4x4.Translate(Source.position);
|
||||
}
|
||||
return parent * m_src.LocalInitial.Matrix;
|
||||
}
|
||||
else if (Source != null)
|
||||
|
||||
return Matrix4x4.identity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Local の座標系。つまり親座標系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Matrix4x4 GetSourceLocalCoords()
|
||||
{
|
||||
if (Source != null)
|
||||
{
|
||||
return Source.localToWorldMatrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Matrix4x4.identity;
|
||||
if (m_src != null)
|
||||
{
|
||||
// runtime
|
||||
var parent = Matrix4x4.identity;
|
||||
if (Source.parent != null)
|
||||
{
|
||||
parent = Source.parent.localToWorldMatrix;
|
||||
}
|
||||
return parent * m_src.LocalInitial.Matrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Source.localToWorldMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
return Matrix4x4.identity;
|
||||
}
|
||||
|
||||
public Quaternion Delta
|
||||
@@ -66,6 +90,7 @@ namespace UniVRM10
|
||||
{
|
||||
if (m_src != null)
|
||||
{
|
||||
// runtime
|
||||
var parent = Matrix4x4.identity;
|
||||
if (transform.parent != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user