Merge pull request #1719 from ousttrue/fix/vrm_keep_animation

vrm の gltf Animation の読み書き仕様
This commit is contained in:
ousttrue 2022-06-29 12:53:20 +09:00 committed by GitHub
commit 46593549d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 520 additions and 22 deletions

View File

@ -13,16 +13,19 @@ namespace UniGLTF
static List<AnimationClip> GetAnimationClips(GameObject Copy)
{
var clips = new List<AnimationClip>();
var animator = Copy.GetComponent<Animator>();
var animation = Copy.GetComponent<Animation>();
if (animator != null)
{
clips = AnimationExporter.GetAnimationClips(animator);
clips.AddRange(AnimationExporter.GetAnimationClips(animator));
}
else if (animation != null)
var animation = Copy.GetComponent<Animation>();
if (animation != null)
{
clips = AnimationExporter.GetAnimationClips(animation);
clips.AddRange(AnimationExporter.GetAnimationClips(animation));
}
return clips;
}

View File

@ -18,6 +18,8 @@ namespace UniGLTF
public TextureFactory TextureFactory { get; }
public MaterialFactory MaterialFactory { get; }
public AnimationClipFactory AnimationClipFactory { get; }
public bool LoadAnimation { get; set; } = true;
public IReadOnlyDictionary<SubAssetKey, UnityEngine.Object> ExternalObjectMap;
/// <summary>
@ -113,10 +115,13 @@ namespace UniGLTF
await LoadGeometryAsync(awaitCaller, MeasureTime);
using (MeasureTime("AnimationImporter"))
if (LoadAnimation)
{
await LoadAnimationAsync(awaitCaller);
await SetupAnimationsAsync(awaitCaller);
using (MeasureTime("AnimationImporter"))
{
await LoadAnimationAsync(awaitCaller);
await SetupAnimationsAsync(awaitCaller);
}
}
await OnLoadHierarchy(awaitCaller, MeasureTime);

View File

@ -223,7 +223,9 @@ namespace VRM
// 出力
var sw = System.Diagnostics.Stopwatch.StartNew();
var data = new UniGLTF.ExportingGltfData();
using (var exporter = new VRMExporter(data, settings.MeshExportSettings))
var gltfExportSettings = settings.GltfExportSettings;
using (var exporter = new VRMExporter(data, gltfExportSettings,
settings.KeepAnimation ? new EditorAnimationExporter() : null))
{
exporter.Prepare(target);
exporter.Export(new EditorTextureSerializer());

View File

@ -61,6 +61,12 @@ namespace VRM
var meshPath = meshDir.Child(o.name.EscapeFilePath() + ".asset");
return meshPath;
}
else if (o is AnimationClip)
{
var meshDir = prefabPath.GetAssetFolder(".Animations");
var meshPath = meshDir.Child(o.name.EscapeFilePath() + ".anim");
return meshPath;
}
else
{
return default(UnityPath);

View File

@ -47,5 +47,9 @@ namespace VRM
[LangMsg(Languages.ja, "頂点カラーの自動削除をしない。")]
[LangMsg(Languages.en, "Do not automatically delete vertex colors.")]
KEEP_VERTEX_COLOR,
[LangMsg(Languages.ja, "glTF Animationをエクスポートする。")]
[LangMsg(Languages.en, "export glTF animation.")]
EXPORT_GLTF_ANIMATION,
}
}

View File

@ -55,7 +55,13 @@ namespace VRM
[Tooltip("Keep vertex color attribute")]
public bool KeepVertexColor = false;
public GltfExportSettings MeshExportSettings => new GltfExportSettings
/// <summary>
/// Export時にAnimationを落とさない。特別な用途で使えるように敢えて残す設定
/// </summary>
[Tooltip("Keep animation")]
public bool KeepAnimation = false;
public GltfExportSettings GltfExportSettings => new GltfExportSettings
{
UseSparseAccessorForMorphTarget = UseSparseAccessor,
ExportOnlyBlendShapePosition = OnlyBlendshapePosition,

View File

@ -54,6 +54,7 @@ namespace VRM
m_checkbox_list.Add(new CheckBoxProp(serializedObject.FindProperty(nameof(VRMExportSettings.ReduceBlendshapeClip)), VRMExportOptions.BLENDSHAPE_EXCLUDE_UNKNOWN));
m_checkbox_list.Add(new CheckBoxProp(serializedObject.FindProperty(nameof(VRMExportSettings.DivideVertexBuffer)), VRMExportOptions.DIVIDE_VERTEX_BUFFER));
m_checkbox_list.Add(new CheckBoxProp(serializedObject.FindProperty(nameof(VRMExportSettings.KeepVertexColor)), VRMExportOptions.KEEP_VERTEX_COLOR));
m_checkbox_list.Add(new CheckBoxProp(serializedObject.FindProperty(nameof(VRMExportSettings.KeepAnimation)), VRMExportOptions.EXPORT_GLTF_ANIMATION));
}

View File

@ -167,7 +167,7 @@ namespace VRM
protected override void OnLayout()
{
m_meshes.SetRoot(State.ExportRoot, m_settings.MeshExportSettings, new VRMBlendShapeExportFilter(State.ExportRoot, m_settings));
m_meshes.SetRoot(State.ExportRoot, m_settings.GltfExportSettings, new VRMBlendShapeExportFilter(State.ExportRoot, m_settings));
}
static bool s_foldT = true;

View File

@ -75,7 +75,7 @@ namespace VRM
// 確実に Dispose するために敢えて再パースしている
using (var data = new GlbFileParser(vrmPath).Parse())
using (var context = new VRMImporterContext(new VRMData(data), externalObjectMap: map))
using (var context = new VRMImporterContext(new VRMData(data), externalObjectMap: map, loadAnimation: true))
{
var editor = new VRMEditorImporterContext(context, prefabPath);
foreach (var textureInfo in context.TextureDescriptorGenerator.Get().GetEnumerable())

View File

@ -25,7 +25,8 @@ namespace VRM
public readonly VRM.glTF_VRM_extensions VRM = new glTF_VRM_extensions();
public VRMExporter(ExportingGltfData data, GltfExportSettings exportSettings) : base(data, exportSettings)
public VRMExporter(ExportingGltfData data, GltfExportSettings exportSettings, IAnimationExporter animationExporter = null) : base(
data, exportSettings, animationExporter: animationExporter)
{
if (exportSettings == null || exportSettings.InverseAxis != Vrm0xSpecificationInverseAxis)
{

View File

@ -25,11 +25,13 @@ namespace VRM
VRMData data,
IReadOnlyDictionary<SubAssetKey, Object> externalObjectMap = null,
ITextureDeserializer textureDeserializer = null,
IMaterialDescriptorGenerator materialGenerator = null)
IMaterialDescriptorGenerator materialGenerator = null,
bool loadAnimation = false)
: base(data.Data, externalObjectMap, textureDeserializer, materialGenerator ?? new VRMMaterialDescriptorGenerator(data.VrmExtension))
{
_data = data;
TextureDescriptorGenerator = new VrmTextureDescriptorGenerator(Data, VRM);
LoadAnimation = loadAnimation;
}
#region OnLoad

View File

@ -14,7 +14,8 @@ namespace VRM
public static async Task<RuntimeGltfInstance> LoadAsync(string path,
IAwaitCaller awaitCaller = null,
MaterialGeneratorCallback materialGeneratorCallback = null,
MetaCallback metaCallback = null
MetaCallback metaCallback = null,
bool loadAnimation = false
)
{
if (!File.Exists(path))
@ -38,7 +39,7 @@ namespace VRM
{
materialGen = materialGeneratorCallback(vrm.VrmExtension);
}
using (var loader = new VRMImporterContext(vrm, materialGenerator: materialGen))
using (var loader = new VRMImporterContext(vrm, materialGenerator: materialGen, loadAnimation: loadAnimation))
{
if (metaCallback != null)
{

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,9 @@ namespace VRM.SimpleViewer
[SerializeField]
Toggle m_useAsync = default;
[SerializeField]
Toggle m_loadAnimation = default;
[SerializeField]
Toggle m_useFastSpringBone = default;
#endregion
@ -386,7 +389,7 @@ namespace VRM.SimpleViewer
{
VrmUtility.MaterialGeneratorCallback materialCallback = (VRM.glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm);
VrmUtility.MetaCallback metaCallback = m_texts.UpdateMeta;
var instance = await VrmUtility.LoadAsync(path, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback);
var instance = await VrmUtility.LoadAsync(path, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback, loadAnimation: m_loadAnimation.isOn);
SetModel(instance);
break;
}