mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-05 20:56:26 -05:00
* MeshUtility を UniGLTF 下に移動 * Assets/VRM10 を追加 * JsonSchemaからのコード生成 UniGLTF/Editor/Generator を追加
81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
|
|
namespace VrmLib
|
|
{
|
|
public static class ModelExtensions
|
|
{
|
|
public static void ApplyRotationAndScale(this Model model)
|
|
{
|
|
// worldPositionを記録する
|
|
var m_positionMap = model.Nodes.ToDictionary(x => x, x => x.Translation);
|
|
|
|
// 回転・拡縮を除去する
|
|
// 木構造の根元から実行する
|
|
// Rootは編集対象外
|
|
foreach (var node in model.Root.Traverse().Skip(1))
|
|
{
|
|
// 回転・拡縮を除去
|
|
if (m_positionMap.TryGetValue(node, out Vector3 pos))
|
|
{
|
|
var t = Matrix4x4.CreateTranslation(pos);
|
|
node.SetMatrix(t, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
// [Debug向け]secondaryを除去
|
|
/// </summary>
|
|
public static void RemoveSecondary(this Model model)
|
|
{
|
|
var secondary = model.Nodes
|
|
.FirstOrDefault(x =>
|
|
(x.Name == "secondary" || x.Name == "SpringBone")
|
|
&& x.Parent == model.Root
|
|
&& x.Children.Count == 0)
|
|
;
|
|
if (secondary != null)
|
|
{
|
|
var mod = new ModelModifier(model);
|
|
mod.NodeRemove(secondary);
|
|
}
|
|
}
|
|
|
|
static void CheckIndex<T>(List<T> list, string name) where T : GltfId
|
|
{
|
|
for (int i = 0; i < list.Count; ++i)
|
|
{
|
|
if (list[i].GltfIndex.HasValue)
|
|
{
|
|
if (list[i].GltfIndex.Value == i)
|
|
{
|
|
Console.WriteLine($"{name}[{i}] => OK");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"{name}[{i}] => {list[i].GltfIndex}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"{name}[{i}] => null");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void CheckIndex(this Model model)
|
|
{
|
|
CheckIndex(model.Images, nameof(model.Images));
|
|
CheckIndex(model.Textures, nameof(model.Textures));
|
|
CheckIndex(model.Materials, nameof(model.Materials));
|
|
CheckIndex(model.Nodes, nameof(model.Nodes));
|
|
CheckIndex(model.Skins, nameof(model.Skins));
|
|
CheckIndex(model.MeshGroups, nameof(model.MeshGroups));
|
|
CheckIndex(model.Animations, nameof(model.Animations));
|
|
}
|
|
}
|
|
}
|