-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- package updates - cleanup unused parts - move export type to common options instead of just layout - use export type for character exports - add option to toggle pose export - add option to include model scaling (used by c+ in meddle exports)
- Loading branch information
1 parent
7994aa5
commit beae632
Showing
27 changed files
with
482 additions
and
2,476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Meddle.Plugin.Models; | ||
|
||
public enum MenuType | ||
{ | ||
Default = 0, | ||
Debug = 1, | ||
Testing = 2, | ||
} | ||
|
||
[Flags] | ||
public enum ExportType | ||
{ | ||
// ReSharper disable InconsistentNaming | ||
GLTF = 1, | ||
GLB = 2, | ||
OBJ = 4 | ||
// ReSharper restore InconsistentNaming | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Meddle/Meddle.Plugin/Services/AnimationExportService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System.Diagnostics; | ||
using System.Numerics; | ||
using Meddle.Plugin.Models; | ||
using Meddle.Plugin.Utils; | ||
using Microsoft.Extensions.Logging; | ||
using SharpGLTF.Geometry; | ||
using SharpGLTF.Geometry.VertexTypes; | ||
using SharpGLTF.Materials; | ||
using SharpGLTF.Scenes; | ||
|
||
namespace Meddle.Plugin.Services; | ||
|
||
public class AnimationExportService : IDisposable, IService | ||
{ | ||
private static readonly ActivitySource ActivitySource = new("Meddle.Plugin.Utils.ExportUtil"); | ||
private readonly Configuration configuration; | ||
private readonly ILogger<AnimationExportService> logger; | ||
|
||
public AnimationExportService(Configuration configuration, ILogger<AnimationExportService> logger) | ||
{ | ||
this.configuration = configuration; | ||
this.logger = logger; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
logger.LogDebug("Disposing ExportUtil"); | ||
} | ||
|
||
public void ExportAnimation(List<(DateTime, AttachSet[])> frames, bool includePositionalData, string path, CancellationToken token = default) | ||
{ | ||
try | ||
{ | ||
using var activity = ActivitySource.StartActivity(); | ||
var boneSets = SkeletonUtils.GetAnimatedBoneMap(frames.ToArray(), configuration.PoseMode); | ||
var startTime = frames.Min(x => x.Item1); | ||
//var folder = GetPathForOutput(); | ||
var folder = path; | ||
Directory.CreateDirectory(folder); | ||
foreach (var (id, (bones, root, timeline)) in boneSets) | ||
{ | ||
var scene = new SceneBuilder(); | ||
if (root == null) throw new InvalidOperationException("Root bone not found"); | ||
logger.LogInformation("Adding bone set {Id}", id); | ||
|
||
if (includePositionalData) | ||
{ | ||
var startPos = timeline.First().Attach.Transform.Translation; | ||
foreach (var frameTime in timeline) | ||
{ | ||
if (token.IsCancellationRequested) return; | ||
var pos = frameTime.Attach.Transform.Translation; | ||
var rot = frameTime.Attach.Transform.Rotation; | ||
var scale = frameTime.Attach.Transform.Scale; | ||
var time = SkeletonUtils.TotalSeconds(frameTime.Time, startTime); | ||
root.UseTranslation().UseTrackBuilder("pose").WithPoint(time, pos - startPos); | ||
root.UseRotation().UseTrackBuilder("pose").WithPoint(time, rot); | ||
root.UseScale().UseTrackBuilder("pose").WithPoint(time, scale); | ||
} | ||
} | ||
|
||
scene.AddNode(root); | ||
scene.AddSkinnedMesh(GetDummyMesh(id), Matrix4x4.Identity, bones.Cast<NodeBuilder>().ToArray()); | ||
var sceneGraph = scene.ToGltf2(); | ||
var outputPath = Path.Combine(folder, $"motion_{id}.gltf"); | ||
sceneGraph.SaveGLTF(outputPath); | ||
} | ||
|
||
Process.Start("explorer.exe", folder); | ||
logger.LogInformation("Export complete"); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e, "Failed to export animation"); | ||
throw; | ||
} | ||
} | ||
|
||
// https://github.com/0ceal0t/Dalamud-VFXEditor/blob/be00131b93b3c6dd4014a4f27c2661093daf3a85/VFXEditor/Utils/Gltf/GltfSkeleton.cs#L132 | ||
public static MeshBuilder<VertexPosition, VertexEmpty, VertexJoints4> GetDummyMesh(string name = "DUMMY_MESH") | ||
{ | ||
var dummyMesh = new MeshBuilder<VertexPosition, VertexEmpty, VertexJoints4>(name); | ||
var material = new MaterialBuilder("material"); | ||
|
||
var p1 = new VertexPosition | ||
{ | ||
Position = new Vector3(0.000001f, 0, 0) | ||
}; | ||
var p2 = new VertexPosition | ||
{ | ||
Position = new Vector3(0, 0.000001f, 0) | ||
}; | ||
var p3 = new VertexPosition | ||
{ | ||
Position = new Vector3(0, 0, 0.000001f) | ||
}; | ||
|
||
dummyMesh.UsePrimitive(material).AddTriangle( | ||
(p1, new VertexEmpty(), new VertexJoints4(0)), | ||
(p2, new VertexEmpty(), new VertexJoints4(0)), | ||
(p3, new VertexEmpty(), new VertexJoints4(0)) | ||
); | ||
|
||
return dummyMesh; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.