using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
namespace Luneraria.EditorTools
{
///
/// The facts and checks that tools/blender/lune_fbx_export.py writes next to every FBX
/// (<id>.export.json). The importer reads the clip data from it; the verifier compares
/// the imported model with the Blender side.
///
public sealed class ExportReport
{
public readonly string Path;
public readonly JObject Data;
ExportReport(string path, JObject data)
{
Path = path;
Data = data;
}
public string Id { get { return (string)Data["id"]; } }
public string Kind { get { return (string)Data["kind"]; } }
public bool Skinned { get { return Kind == "skinned"; } }
public bool BlenderOk { get { return (bool)Data["ok"]; } }
public JObject Meshes { get { return (JObject)Data["meshes"]; } }
public JArray Clips { get { return (JArray)Data["clips"] ?? new JArray(); } }
/// Report of an FBX asset path, or null if the model was not exported by the pipeline.
public static ExportReport ForModel(string modelPath)
{
string path = System.IO.Path.ChangeExtension(modelPath, ".export.json");
if (!File.Exists(path))
return null;
return new ExportReport(path, JObject.Parse(File.ReadAllText(path)));
}
public static IEnumerable AllModels(string root)
{
foreach (string path in Directory.GetFiles(root, "*.export.json", SearchOption.AllDirectories))
yield return path.Replace('\\', '/').Replace(".export.json", ".fbx");
}
}
}