mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 13:29:41 -05:00
fix NormalizeNoneSkinnedMesh
This commit is contained in:
@@ -9,7 +9,7 @@ namespace UniGLTF.MeshUtility
|
||||
{
|
||||
public static class BoneNormalizer
|
||||
{
|
||||
private static MeshAttachInfo CreateMeshInfo(Transform src)
|
||||
private static MeshAttachInfo CreateMeshInfo(Transform src, bool freezeRotation)
|
||||
{
|
||||
// SkinnedMeshRenderer
|
||||
var smr = src.GetComponent<SkinnedMeshRenderer>();
|
||||
@@ -29,7 +29,7 @@ namespace UniGLTF.MeshUtility
|
||||
var mr = src.GetComponent<MeshRenderer>();
|
||||
if (mr != null)
|
||||
{
|
||||
var dstMesh = MeshFreezer.NormalizeNoneSkinnedMesh(mr);
|
||||
var dstMesh = MeshFreezer.NormalizeNoneSkinnedMesh(mr, freezeRotation);
|
||||
if (dstMesh != null)
|
||||
{
|
||||
return new MeshAttachInfo
|
||||
@@ -48,12 +48,13 @@ namespace UniGLTF.MeshUtility
|
||||
/// 各レンダラー(SkinnedMeshRenderer と MeshRenderer)にアタッチされた sharedMesh に対して
|
||||
/// 回転とスケールを除去し、BlendShape の現状を焼き付けた版を作成する(まだ、アタッチしない)
|
||||
/// </summary>
|
||||
public static Dictionary<Transform, MeshAttachInfo> NormalizeHierarchyFreezeMesh(GameObject go)
|
||||
public static Dictionary<Transform, MeshAttachInfo> NormalizeHierarchyFreezeMesh(
|
||||
GameObject go, bool freezeRotation)
|
||||
{
|
||||
var result = new Dictionary<Transform, MeshAttachInfo>();
|
||||
foreach (var src in go.transform.Traverse())
|
||||
{
|
||||
var info = CreateMeshInfo(src);
|
||||
var info = CreateMeshInfo(src, freezeRotation);
|
||||
if (info != null)
|
||||
{
|
||||
result.Add(src, info);
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace UniGLTF.MeshUtility
|
||||
if (FreezeBlendShape || FreezeRotation || FreezeScaling)
|
||||
{
|
||||
// MeshをBakeする
|
||||
var newMesh = BoneNormalizer.NormalizeHierarchyFreezeMesh(target);
|
||||
var newMesh = BoneNormalizer.NormalizeHierarchyFreezeMesh(target, FreezeRotation);
|
||||
|
||||
// - ヒエラルキーから回転・拡縮を除去する
|
||||
// - BakeされたMeshで置き換える
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using VRMShaders;
|
||||
|
||||
namespace UniGLTF.MeshUtility
|
||||
@@ -330,7 +331,7 @@ namespace UniGLTF.MeshUtility
|
||||
}
|
||||
}
|
||||
|
||||
public static Mesh NormalizeNoneSkinnedMesh(MeshRenderer srcRenderer)
|
||||
public static Mesh NormalizeNoneSkinnedMesh(MeshRenderer srcRenderer, bool freezeRotation)
|
||||
{
|
||||
if (srcRenderer == null || !srcRenderer.enabled)
|
||||
{
|
||||
@@ -347,7 +348,15 @@ namespace UniGLTF.MeshUtility
|
||||
|
||||
var dstMesh = srcFilter.sharedMesh.Copy(false);
|
||||
// Meshに乗っているボーンの姿勢を適用する
|
||||
dstMesh.ApplyRotationAndScale(srcRenderer.transform.localToWorldMatrix);
|
||||
if (freezeRotation)
|
||||
{
|
||||
dstMesh.ApplyRotationAndScale(srcRenderer.transform.localToWorldMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
var (t, r, s) = srcRenderer.transform.localToWorldMatrix.Decompose();
|
||||
dstMesh.ApplyRotationAndScale(Matrix4x4.TRS(t, Quaternion.identity, s));
|
||||
}
|
||||
return dstMesh;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace VRM
|
||||
}
|
||||
|
||||
// Meshの焼きこみ
|
||||
var newMesh = BoneNormalizer.NormalizeHierarchyFreezeMesh(go);
|
||||
var newMesh = BoneNormalizer.NormalizeHierarchyFreezeMesh(go, true);
|
||||
// 焼いたMeshで置き換える
|
||||
BoneNormalizer.Replace(go, newMesh, true, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user