Code commit

This commit is contained in:
RisaDev
2024-01-06 01:21:41 +03:00
parent a7d7297c59
commit a486dd2c96
90 changed files with 11576 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
using CustomizePlus.Anamnesis.Data;
using CustomizePlus.Core.Data;
using CustomizePlus.Core.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
namespace CustomizePlus.Anamnesis;
public class PoseFileBoneLoader
{
public Dictionary<string, BoneTransform>? LoadBoneTransformsFromFile(string path)
{
if (!File.Exists(path))
return null;
var json = File.ReadAllText(path);
JsonSerializerSettings settings = new()
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new PoseFile.VectorConverter() }
};
var pose = JsonConvert.DeserializeObject<PoseFile>(json, settings);
if (pose == null)
{
throw new Exception("Failed to deserialize pose file");
}
if (pose.Bones == null)
{
return null;
}
var retDict = new Dictionary<string, BoneTransform>();
foreach (var kvp in pose.Bones)
{
if (kvp.Key == Constants.RootBoneName || kvp.Value == null || kvp.Value.Scale == null)
continue;
var scale = kvp.Value!.Scale!.GetAsNumericsVector();
if (scale == Vector3.One)
continue;
retDict[kvp.Key] = new BoneTransform
{
Scaling = scale
};
}
//load up root, but check it more rigorously
var validRoot = pose.Bones.TryGetValue(Constants.RootBoneName, out var root)
&& root != null
&& root.Scale != null
&& root.Scale.GetAsNumericsVector() != Vector3.Zero
&& root.Scale.GetAsNumericsVector() != Vector3.One;
if (validRoot)
{
retDict[Constants.RootBoneName] = new BoneTransform
{
Scaling = root!.Scale!.GetAsNumericsVector()
};
}
return retDict;
}
}