mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-16 07:34:05 -05:00
Merge pull request #1719 from ousttrue/fix/vrm_keep_animation
vrm の gltf Animation の読み書き仕様
This commit is contained in:
commit
46593549d9
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user