Skip to content

Commit

Permalink
Add gltf2skn CLI option (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crauzer authored Feb 2, 2023
1 parent fa666b4 commit 9bdc93e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lol2gltf.CLI/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public class SkinnedMeshToGltfOptions
public IEnumerable<string> 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
{
Expand Down
25 changes: 24 additions & 1 deletion lol2gltf.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,10 +25,11 @@ class Program
static void Main(string[] args)
{
CommandLine.Parser.Default
.ParseArguments<SkinnedMeshToGltfOptions, MapGeometryToGltfOptions>(args)
.ParseArguments<SkinnedMeshToGltfOptions, MapGeometryToGltfOptions, GltfToSkinnedMeshOptions>(args)
.MapResult(
(SkinnedMeshToGltfOptions opts) => ConvertSkinnedMeshToGltf(opts),
(MapGeometryToGltfOptions opts) => ConvertMapGeometryToGltf(opts),
(GltfToSkinnedMeshOptions opts) => ConvertGltfToSkinnedMesh(opts),
HandleErrors
);
}
Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 4 additions & 0 deletions lol2gltf.CLI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
4 changes: 2 additions & 2 deletions lol2gltf.CLI/lol2gltf.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="LeagueToolkit" Version="4.0.0-beta.5" />
<PackageReference Include="LeagueToolkit.IO.Extensions" Version="4.0.0-beta.5" />
<PackageReference Include="LeagueToolkit" Version="4.0.0-beta.6" />
<PackageReference Include="LeagueToolkit.IO.Extensions" Version="4.0.0-beta.6" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>

Expand Down

0 comments on commit 9bdc93e

Please sign in to comment.