mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 05:44:48 -05:00
export position constraint
This commit is contained in:
@@ -35,7 +35,7 @@ namespace UniVRM10
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyTranslation(Vector3 delta, float weight)
|
public void ApplyTranslation(Vector3 delta, float weight, Transform modelRoot = null)
|
||||||
{
|
{
|
||||||
var value = m_initial.Translation + delta * weight;
|
var value = m_initial.Translation + delta * weight;
|
||||||
switch (m_coords)
|
switch (m_coords)
|
||||||
@@ -48,6 +48,10 @@ namespace UniVRM10
|
|||||||
m_transform.localPosition = value;
|
m_transform.localPosition = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ObjectSpace.model:
|
||||||
|
m_transform.position = modelRoot.localToWorldMatrix.MultiplyPoint(value);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace UniVRM10
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
public Transform Source = default;
|
public Transform Source = default;
|
||||||
|
|
||||||
// [SerializeField]
|
[SerializeField]
|
||||||
// [Range(0, 10.0f)]
|
[Range(0, 10.0f)]
|
||||||
// float Weight = 1.0f;
|
public float Weight = 1.0f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Forward
|
/// Forward
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace UniVRM10
|
|||||||
}
|
}
|
||||||
|
|
||||||
var delta = FreezeAxes.Freeze(m_src.TranslationDelta);
|
var delta = FreezeAxes.Freeze(m_src.TranslationDelta);
|
||||||
m_dst.ApplyTranslation(delta, Weight);
|
m_dst.ApplyTranslation(delta, Weight, ModelRoot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,10 @@ namespace UniVRM10
|
|||||||
var mesh = CreateMesh(filter.sharedMesh, meshRenderer, Materials);
|
var mesh = CreateMesh(filter.sharedMesh, meshRenderer, Materials);
|
||||||
Model.MeshGroups.Add(mesh);
|
Model.MeshGroups.Add(mesh);
|
||||||
Nodes[renderer.gameObject].MeshGroup = mesh;
|
Nodes[renderer.gameObject].MeshGroup = mesh;
|
||||||
Meshes.Add(filter.sharedMesh, mesh);
|
if (!Meshes.ContainsKey(filter.sharedMesh))
|
||||||
|
{
|
||||||
|
Meshes.Add(filter.sharedMesh, mesh);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,29 +358,31 @@ namespace UniVRM10
|
|||||||
var constraints = vrmController.GetComponentsInChildren<VRM10Constraint>();
|
var constraints = vrmController.GetComponentsInChildren<VRM10Constraint>();
|
||||||
foreach (var constraint in constraints)
|
foreach (var constraint in constraints)
|
||||||
{
|
{
|
||||||
|
UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint vrmConstraint = default;
|
||||||
switch (constraint)
|
switch (constraint)
|
||||||
{
|
{
|
||||||
case VRM10PositionConstraint positionConstraint:
|
case VRM10PositionConstraint positionConstraint:
|
||||||
ExportPostionConstraint(positionConstraint, model, converter);
|
vrmConstraint = ExportPostionConstraint(positionConstraint, model, converter);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VRM10RotationConstraint rotationConstraint:
|
case VRM10RotationConstraint rotationConstraint:
|
||||||
ExportRotationConstraint(rotationConstraint, model, converter);
|
vrmConstraint = ExportRotationConstraint(rotationConstraint, model, converter);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VRM10AimConstraint aimConstraint:
|
case VRM10AimConstraint aimConstraint:
|
||||||
ExportAimConstraint(aimConstraint, model, converter);
|
vrmConstraint = ExportAimConstraint(aimConstraint, model, converter);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExportPostionConstraint(VRM10PositionConstraint c, Model model, RuntimeVrmConverter converter)
|
// serialize to gltfNode
|
||||||
{
|
var node = converter.Nodes[constraint.gameObject];
|
||||||
throw new NotImplementedException();
|
var nodeIndex = model.Nodes.IndexOf(node);
|
||||||
|
var gltfNode = Storage.Gltf.nodes[nodeIndex];
|
||||||
|
UniGLTF.Extensions.VRMC_node_constraint.GltfSerializer.SerializeTo(ref gltfNode.extensions, vrmConstraint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool[] ToArray(AxisMask mask)
|
static bool[] ToArray(AxisMask mask)
|
||||||
@@ -393,9 +395,27 @@ namespace UniVRM10
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportRotationConstraint(VRM10RotationConstraint c, Model model, RuntimeVrmConverter converter)
|
static UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint ExportPostionConstraint(VRM10PositionConstraint c, Model model, RuntimeVrmConverter converter)
|
||||||
{
|
{
|
||||||
var vrmConstraint = new UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint
|
return new UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint
|
||||||
|
{
|
||||||
|
Constraint = new UniGLTF.Extensions.VRMC_node_constraint.Constraint
|
||||||
|
{
|
||||||
|
Position = new UniGLTF.Extensions.VRMC_node_constraint.PositionConstraint
|
||||||
|
{
|
||||||
|
Source = model.Nodes.IndexOf(converter.Nodes[c.Source.gameObject]),
|
||||||
|
SourceSpace = c.SourceCoordinate,
|
||||||
|
DestinationSpace = c.DestinationCoordinate,
|
||||||
|
FreezeAxes = ToArray(c.FreezeAxes),
|
||||||
|
Weight = c.Weight,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint ExportRotationConstraint(VRM10RotationConstraint c, Model model, RuntimeVrmConverter converter)
|
||||||
|
{
|
||||||
|
return new UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint
|
||||||
{
|
{
|
||||||
Constraint = new UniGLTF.Extensions.VRMC_node_constraint.Constraint
|
Constraint = new UniGLTF.Extensions.VRMC_node_constraint.Constraint
|
||||||
{
|
{
|
||||||
@@ -409,17 +429,23 @@ namespace UniVRM10
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// serialize to gltfNode
|
|
||||||
var node = converter.Nodes[c.gameObject];
|
|
||||||
var nodeIndex = model.Nodes.IndexOf(node);
|
|
||||||
var gltfNode = Storage.Gltf.nodes[nodeIndex];
|
|
||||||
UniGLTF.Extensions.VRMC_node_constraint.GltfSerializer.SerializeTo(ref gltfNode.extensions, vrmConstraint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExportAimConstraint(VRM10AimConstraint c, Model model, RuntimeVrmConverter converter)
|
static UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint ExportAimConstraint(VRM10AimConstraint c, Model model, RuntimeVrmConverter converter)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return new UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint
|
||||||
|
{
|
||||||
|
Constraint = new UniGLTF.Extensions.VRMC_node_constraint.Constraint
|
||||||
|
{
|
||||||
|
Aim = new UniGLTF.Extensions.VRMC_node_constraint.AimConstraint
|
||||||
|
{
|
||||||
|
Source = model.Nodes.IndexOf(converter.Nodes[c.Source.gameObject]),
|
||||||
|
AimVector = ReverseX(c.AimVector),
|
||||||
|
UpVector = ReverseX(c.UpVector),
|
||||||
|
Weight = c.Weight,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniGLTF.Extensions.VRMC_vrm.MeshAnnotation ExportMeshAnnotation(RendererFirstPersonFlags flags, Func<Renderer, int> getIndex)
|
static UniGLTF.Extensions.VRMC_vrm.MeshAnnotation ExportMeshAnnotation(RendererFirstPersonFlags flags, Func<Renderer, int> getIndex)
|
||||||
|
|||||||
Reference in New Issue
Block a user