diff --git a/lol2gltf.CLI/Options.cs b/lol2gltf.CLI/Options.cs index cc0d18a..6f11e48 100644 --- a/lol2gltf.CLI/Options.cs +++ b/lol2gltf.CLI/Options.cs @@ -35,6 +35,24 @@ public class SkinnedMeshToGltfOptions public IEnumerable TexturePaths { get; set; } } + [Verb("gltf2skn", HelpText = "Converts a glTF asset into a Skinned Mesh (.skn, .skl)")] + public class GltfToSkinnedMeshOptions + { + [Option('g', "gltf", Required = true, HelpText = "glTF Asset (.glb, .gltf) path")] + public string GltfPath { get; set; } + + [Option('m', "skn", Required = true, HelpText = "Simple Skin (.skn) path")] + public string SimpleSkinPath { get; set; } + + [Option( + 's', + "skl", + Required = false, + HelpText = "Skeleton (.skl) path (if not specified, will be saved under the same name as the Simple Skin)" + )] + public string SkeletonPath { get; set; } + } + [Verb("mapgeo2gltf", HelpText = "Converts Map Geometry into a glTF asset")] public class MapGeometryToGltfOptions { diff --git a/lol2gltf.CLI/Program.cs b/lol2gltf.CLI/Program.cs index 605b81a..bf94126 100644 --- a/lol2gltf.CLI/Program.cs +++ b/lol2gltf.CLI/Program.cs @@ -8,6 +8,7 @@ using LeagueToolkit.IO.SimpleSkinFile; using LeagueToolkit.Meta; using LeagueToolkit.Toolkit; +using SharpGLTF.Schema2; using SixLabors.ImageSharp; using System; using System.Collections.Generic; @@ -24,10 +25,11 @@ class Program static void Main(string[] args) { CommandLine.Parser.Default - .ParseArguments(args) + .ParseArguments(args) .MapResult( (SkinnedMeshToGltfOptions opts) => ConvertSkinnedMeshToGltf(opts), (MapGeometryToGltfOptions opts) => ConvertMapGeometryToGltf(opts), + (GltfToSkinnedMeshOptions opts) => ConvertGltfToSkinnedMesh(opts), HandleErrors ); } @@ -74,6 +76,27 @@ private static int ConvertSkinnedMeshToGltf(SkinnedMeshToGltfOptions options) return 1; } + private static int ConvertGltfToSkinnedMesh(GltfToSkinnedMeshOptions options) + { + string skeletonPath = string.IsNullOrEmpty(options.SkeletonPath) switch + { + true => Path.ChangeExtension(options.SimpleSkinPath, "skl"), + false => options.SkeletonPath + }; + + ModelRoot gltf = ModelRoot.Load(options.GltfPath); + + var (simpleSkin, rig) = gltf.ToRiggedMesh(); + + using FileStream simpleSkinStream = File.Create(options.SimpleSkinPath); + simpleSkin.WriteSimpleSkin(simpleSkinStream); + + using FileStream rigStream = File.Create(skeletonPath); + rig.Write(rigStream); + + return 1; + } + private static int ConvertMapGeometryToGltf(MapGeometryToGltfOptions options) { MapGeometryGltfConversionContext conversionContext = diff --git a/lol2gltf.CLI/Properties/launchSettings.json b/lol2gltf.CLI/Properties/launchSettings.json index c9afdd8..4a9ff05 100644 --- a/lol2gltf.CLI/Properties/launchSettings.json +++ b/lol2gltf.CLI/Properties/launchSettings.json @@ -7,6 +7,10 @@ "mapgeo2gltf": { "commandName": "Project", "commandLineArgs": "mapgeo2gltf -m X:/lol/game/data/maps/mapgeometry/map11/base_srx.mapgeo -b X:/lol/game/data/maps/mapgeometry/map11/base_srx.materials.bin -g base_srx.glb" + }, + "gltf2skn": { + "commandName": "Project", + "commandLineArgs": "gltf2skn -g akali.glb -m akali.skn -s akali.skl" } } } \ No newline at end of file diff --git a/lol2gltf.CLI/lol2gltf.CLI.csproj b/lol2gltf.CLI/lol2gltf.CLI.csproj index 4734879..5eb0211 100644 --- a/lol2gltf.CLI/lol2gltf.CLI.csproj +++ b/lol2gltf.CLI/lol2gltf.CLI.csproj @@ -17,8 +17,8 @@ - - + +