mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 20:08:53 -05:00
IAxisInverter
This commit is contained in:
@@ -240,6 +240,7 @@ namespace UniGLTF
|
||||
// export
|
||||
Export(root, path, new MeshExportSettings
|
||||
{
|
||||
InvertAxis = settings.InverseAxis,
|
||||
ExportOnlyBlendShapePosition = settings.DropNormal,
|
||||
UseSparseAccessorForMorphTarget = settings.Sparse,
|
||||
});
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace UniGLTF
|
||||
return string.Join("/", path);
|
||||
}
|
||||
|
||||
public static AnimationClip ConvertAnimationClip(glTF gltf, glTFAnimation animation, AxisInverter inverter, glTFNode root = null)
|
||||
public static AnimationClip ConvertAnimationClip(glTF gltf, glTFAnimation animation, IAxisInverter inverter, glTFNode root = null)
|
||||
{
|
||||
var clip = new AnimationClip();
|
||||
clip.ClearCurves();
|
||||
|
||||
@@ -9,27 +9,70 @@ namespace UniGLTF
|
||||
X,
|
||||
}
|
||||
|
||||
public struct AxisInverter
|
||||
public interface IAxisInverter
|
||||
{
|
||||
public Func<Vector3, Vector3> InvertVector3;
|
||||
public Func<Vector4, Vector4> InvertVector4;
|
||||
public Func<Quaternion, Quaternion> InvertQuaternion;
|
||||
public Func<Matrix4x4, Matrix4x4> InvertMat4;
|
||||
Vector3 InvertVector3(Vector3 src);
|
||||
Vector4 InvertVector4(Vector4 src);
|
||||
Quaternion InvertQuaternion(Quaternion src);
|
||||
Matrix4x4 InvertMat4(Matrix4x4 src);
|
||||
}
|
||||
|
||||
public static AxisInverter ReverseZ => new AxisInverter
|
||||
public struct ReverseZ : IAxisInverter
|
||||
{
|
||||
public Matrix4x4 InvertMat4(Matrix4x4 src)
|
||||
{
|
||||
InvertVector3 = x => x.ReverseZ(),
|
||||
InvertVector4 = x => x.ReverseZ(),
|
||||
InvertQuaternion = x => x.ReverseZ(),
|
||||
InvertMat4 = x => x.ReverseZ(),
|
||||
};
|
||||
return src.ReverseZ();
|
||||
}
|
||||
|
||||
public static AxisInverter ReverseX => new AxisInverter
|
||||
public Quaternion InvertQuaternion(Quaternion src)
|
||||
{
|
||||
InvertVector3 = x => x.ReverseX(),
|
||||
InvertVector4 = x => x.ReverseX(),
|
||||
InvertQuaternion = x => x.ReverseX(),
|
||||
InvertMat4 = x => x.ReverseX(),
|
||||
};
|
||||
return src.ReverseZ();
|
||||
}
|
||||
|
||||
public Vector3 InvertVector3(Vector3 src)
|
||||
{
|
||||
return src.ReverseZ();
|
||||
}
|
||||
|
||||
public Vector4 InvertVector4(Vector4 src)
|
||||
{
|
||||
return src.ReverseZ();
|
||||
}
|
||||
}
|
||||
|
||||
public class ReverseX : IAxisInverter
|
||||
{
|
||||
public Matrix4x4 InvertMat4(Matrix4x4 src)
|
||||
{
|
||||
return src.ReverseX();
|
||||
}
|
||||
|
||||
public Quaternion InvertQuaternion(Quaternion src)
|
||||
{
|
||||
return src.ReverseX();
|
||||
}
|
||||
|
||||
public Vector3 InvertVector3(Vector3 src)
|
||||
{
|
||||
return src.ReverseX();
|
||||
}
|
||||
|
||||
public Vector4 InvertVector4(Vector4 src)
|
||||
{
|
||||
return src.ReverseX();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AxisesExtensions
|
||||
{
|
||||
public static IAxisInverter Create(this Axises axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case Axises.Z: return new ReverseZ();
|
||||
case Axises.X: return new ReverseX();
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,20 +71,7 @@ namespace UniGLTF
|
||||
MeasureTime = new ImporterContextSpeedLog().MeasureTime;
|
||||
}
|
||||
|
||||
AxisInverter inverter = default;
|
||||
switch (InvertAxis)
|
||||
{
|
||||
case Axises.Z:
|
||||
inverter = AxisInverter.ReverseZ;
|
||||
break;
|
||||
|
||||
case Axises.X:
|
||||
inverter = AxisInverter.ReverseX;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
var inverter = InvertAxis.Create();
|
||||
|
||||
if (Root == null)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace UniGLTF
|
||||
[Serializable]
|
||||
public struct MeshExportSettings
|
||||
{
|
||||
// 反転軸
|
||||
public Axises InvertAxis;
|
||||
|
||||
// MorphTarget に Sparse Accessor を使う
|
||||
public bool UseSparseAccessorForMorphTarget;
|
||||
|
||||
@@ -16,6 +19,7 @@ namespace UniGLTF
|
||||
|
||||
public static MeshExportSettings Default => new MeshExportSettings
|
||||
{
|
||||
InvertAxis = Axises.Z,
|
||||
UseSparseAccessorForMorphTarget = false,
|
||||
ExportOnlyBlendShapePosition = false,
|
||||
};
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace UniGLTF
|
||||
/// <param name="ctx"></param>
|
||||
/// <param name="gltfMesh"></param>
|
||||
/// <returns></returns>
|
||||
public void ImportMeshIndependentVertexBuffer(ImporterContext ctx, glTFMesh gltfMesh, AxisInverter inverter)
|
||||
public void ImportMeshIndependentVertexBuffer(ImporterContext ctx, glTFMesh gltfMesh, IAxisInverter inverter)
|
||||
{
|
||||
foreach (var prim in gltfMesh.primitives)
|
||||
{
|
||||
@@ -291,7 +291,7 @@ namespace UniGLTF
|
||||
/// <param name="ctx"></param>
|
||||
/// <param name="gltfMesh"></param>
|
||||
/// <returns></returns>
|
||||
public void ImportMeshSharingVertexBuffer(ImporterContext ctx, glTFMesh gltfMesh, AxisInverter inverter)
|
||||
public void ImportMeshSharingVertexBuffer(ImporterContext ctx, glTFMesh gltfMesh, IAxisInverter inverter)
|
||||
{
|
||||
{
|
||||
// 同じVertexBufferを共有しているので先頭のモノを使う
|
||||
@@ -507,7 +507,7 @@ namespace UniGLTF
|
||||
return sharedAttributes;
|
||||
}
|
||||
|
||||
public MeshContext ReadMesh(ImporterContext ctx, int meshIndex, AxisInverter inverter)
|
||||
public MeshContext ReadMesh(ImporterContext ctx, int meshIndex, IAxisInverter inverter)
|
||||
{
|
||||
var gltfMesh = ctx.GLTF.meshes[meshIndex];
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace UniGLTF
|
||||
//
|
||||
// fix node's coordinate. z-back to z-forward
|
||||
//
|
||||
public static void FixCoordinate(ImporterContext context, List<TransformWithSkin> nodes, AxisInverter inverter)
|
||||
public static void FixCoordinate(ImporterContext context, List<TransformWithSkin> nodes, IAxisInverter inverter)
|
||||
{
|
||||
var globalTransformMap = nodes.ToDictionary(x => x.Transform, x => new PosRot
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetupSkinning(ImporterContext context, List<TransformWithSkin> nodes, int i, AxisInverter inverter)
|
||||
public static void SetupSkinning(ImporterContext context, List<TransformWithSkin> nodes, int i, IAxisInverter inverter)
|
||||
{
|
||||
var x = nodes[i];
|
||||
var skinnedMeshRenderer = x.Transform.GetComponent<SkinnedMeshRenderer>();
|
||||
|
||||
@@ -46,26 +46,10 @@ namespace UniGLTF
|
||||
animation.name = $"animation:{i}";
|
||||
}
|
||||
|
||||
AxisInverter inverter = default;
|
||||
switch (invertAxis)
|
||||
{
|
||||
case Axises.X:
|
||||
inverter = AxisInverter.ReverseX;
|
||||
break;
|
||||
|
||||
case Axises.Z:
|
||||
inverter = AxisInverter.ReverseZ;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new System.Exception();
|
||||
|
||||
}
|
||||
|
||||
animationClips.Add(AnimationImporterUtil.ConvertAnimationClip(gltf, animation, inverter));
|
||||
animationClips.Add(AnimationImporterUtil.ConvertAnimationClip(gltf, animation, invertAxis.Create()));
|
||||
}
|
||||
|
||||
return animationClips;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user