mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 05:44:48 -05:00
SkinningBake
This commit is contained in:
@@ -11,7 +11,7 @@ namespace UniVRM10
|
||||
{
|
||||
const string MENU_KEY = VRMVersion.MENU + "/SpringBone Window";
|
||||
|
||||
[MenuItem(MENU_KEY, false, 0)]
|
||||
[MenuItem(MENU_KEY, false, 1)]
|
||||
private static void ExportFromMenu()
|
||||
{
|
||||
var window = (VRM10SpringSelectorWindow)GetWindow(typeof(VRM10SpringSelectorWindow));
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace UniVRM10
|
||||
{
|
||||
const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0";
|
||||
|
||||
[MenuItem(CONVERT_HUMANOID_KEY, false, 1)]
|
||||
[MenuItem(CONVERT_HUMANOID_KEY, false, 0)]
|
||||
private static void ExportFromMenu()
|
||||
{
|
||||
var window = (VRM10ExportDialog)GetWindow(typeof(VRM10ExportDialog));
|
||||
@@ -284,13 +284,13 @@ namespace UniVRM10
|
||||
var converter = new UniVRM10.RuntimeVrmConverter();
|
||||
var model = converter.ToModelFrom10(root);
|
||||
|
||||
// if (MeshUtility.Validators.HumanoidValidator.HasRotationOrScale(root))
|
||||
// {
|
||||
// // 正規化
|
||||
// m_logLabel += $"normalize...\n";
|
||||
// var modifier = new ModelModifier(model);
|
||||
// modifier.SkinningBake();
|
||||
// }
|
||||
if (HumanoidValidator.HasRotationOrScale(root))
|
||||
{
|
||||
// 正規化
|
||||
m_logLabel += $"normalize...\n";
|
||||
var modifier = new ModelModifier(model);
|
||||
modifier.SkinningBake();
|
||||
}
|
||||
|
||||
// 右手系に変換
|
||||
m_logLabel += $"convert to right handed coordinate...\n";
|
||||
|
||||
@@ -72,6 +72,6 @@ namespace VrmLib
|
||||
CheckIndex(model.Skins, nameof(model.Skins));
|
||||
CheckIndex(model.MeshGroups, nameof(model.MeshGroups));
|
||||
CheckIndex(model.Animations, nameof(model.Animations));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
81
Assets/VRM10/vrmlib/Runtime/ModelModifierExtensions.cs
Normal file
81
Assets/VRM10/vrmlib/Runtime/ModelModifierExtensions.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
public static class ModelModifierExtensions
|
||||
{
|
||||
public static string SkinningBake(this ModelModifier modifier)
|
||||
{
|
||||
foreach (var node in modifier.Model.Nodes)
|
||||
{
|
||||
var meshGroup = node.MeshGroup;
|
||||
if (meshGroup == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (meshGroup.Skin != null)
|
||||
{
|
||||
// 正規化されていれば1つしかない
|
||||
// されていないと Primitive の数だけある
|
||||
foreach (var mesh in meshGroup.Meshes)
|
||||
{
|
||||
{
|
||||
// Skinningの出力先を自身にすることでBakeする
|
||||
meshGroup.Skin.Skinning(mesh.VertexBuffer);
|
||||
}
|
||||
|
||||
// morphのPositionは相対値が入っているはずなので、手を加えない(正規化されていない場合、二重に補正が掛かる)
|
||||
/*
|
||||
foreach (var morph in mesh.MorphTargets)
|
||||
{
|
||||
if (morph.VertexBuffer.Positions != null)
|
||||
{
|
||||
meshGroup.Skin.Skinning(morph.VertexBuffer);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
meshGroup.Skin.Root = null;
|
||||
meshGroup.Skin.InverseMatrices = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var mesh in meshGroup.Meshes)
|
||||
{
|
||||
// nodeに対して疑似的にSkinningする
|
||||
// 回転と拡縮を適用し位置は適用しない
|
||||
mesh.ApplyRotationAndScaling(node.Matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 回転・拡縮を除去する
|
||||
modifier.Model.ApplyRotationAndScale();
|
||||
|
||||
// inverse matrix の再計算
|
||||
foreach (var node in modifier.Model.Nodes)
|
||||
{
|
||||
var meshGroup = node.MeshGroup;
|
||||
if (meshGroup == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var mesh in meshGroup.Meshes)
|
||||
{
|
||||
if (meshGroup.Skin != null)
|
||||
{
|
||||
meshGroup.Skin.CalcInverseMatrices();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "SkinningBake";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/vrmlib/Runtime/ModelModifierExtensions.cs.meta
Normal file
11
Assets/VRM10/vrmlib/Runtime/ModelModifierExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54fd566dc84b51643886ce8858a671db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user