mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 03:48:19 -05:00
remove arg and return from NormalizeSkinnedMesh.
This commit is contained in:
@@ -71,7 +71,7 @@ namespace UniGLTF.MeshUtility
|
||||
}
|
||||
}
|
||||
|
||||
public static MeshAttachInfo CreateMeshInfo(Transform src, Dictionary<Transform, Transform> boneMap, bool freezeBlendShape)
|
||||
public static MeshAttachInfo CreateMeshInfo(Transform src, Dictionary<Transform, Transform> boneMap)
|
||||
{
|
||||
Transform dst;
|
||||
if (!boneMap.TryGetValue(src, out dst))
|
||||
@@ -81,11 +81,9 @@ namespace UniGLTF.MeshUtility
|
||||
|
||||
// SkinnedMeshRenderer
|
||||
var smr = src.GetComponent<SkinnedMeshRenderer>();
|
||||
var (mesh, dstBones) = MeshFreezer.NormalizeSkinnedMesh(
|
||||
var mesh = MeshFreezer.NormalizeSkinnedMesh(
|
||||
smr,
|
||||
boneMap,
|
||||
dst.localToWorldMatrix,
|
||||
freezeBlendShape);
|
||||
boneMap);
|
||||
if (mesh != null)
|
||||
{
|
||||
var info = new MeshAttachInfo
|
||||
@@ -132,8 +130,7 @@ namespace UniGLTF.MeshUtility
|
||||
public static (GameObject, Dictionary<Transform, Transform>, Dictionary<Transform, MeshAttachInfo>) NormalizeHierarchyFreezeMesh(
|
||||
GameObject go,
|
||||
bool removeScaling = true,
|
||||
bool removeRotation = true,
|
||||
bool freezeBlendShape = true
|
||||
bool removeRotation = true
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -147,7 +144,7 @@ namespace UniGLTF.MeshUtility
|
||||
var result = new Dictionary<Transform, MeshAttachInfo>();
|
||||
foreach (var src in go.transform.Traverse())
|
||||
{
|
||||
var info = CreateMeshInfo(src, boneMap, freezeBlendShape);
|
||||
var info = CreateMeshInfo(src, boneMap);
|
||||
if (info != null)
|
||||
{
|
||||
result.Add(src, info);
|
||||
|
||||
@@ -164,8 +164,7 @@ namespace UniGLTF.MeshUtility
|
||||
{
|
||||
var (normalized, boneMap, newMesh) = BoneNormalizer.NormalizeHierarchyFreezeMesh(go,
|
||||
removeScaling: FreezeScaling,
|
||||
removeRotation: FreezeRotation,
|
||||
freezeBlendShape: FreezeBlendShape);
|
||||
removeRotation: FreezeRotation);
|
||||
|
||||
foreach (var (k, v) in newMesh)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF.MeshUtility
|
||||
@@ -12,6 +13,9 @@ namespace UniGLTF.MeshUtility
|
||||
{
|
||||
if (Bones != null)
|
||||
{
|
||||
// recalc bindposes
|
||||
Mesh.bindposes = Bones.Select(x => x.worldToLocalMatrix * dst.transform.localToWorldMatrix).ToArray();
|
||||
|
||||
var dstRenderer = dst.AddComponent<SkinnedMeshRenderer>();
|
||||
dstRenderer.sharedMesh = Mesh;
|
||||
dstRenderer.sharedMaterials = Materials;
|
||||
|
||||
@@ -126,14 +126,11 @@ namespace UniGLTF.MeshUtility
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="boneMap">正規化前のボーンから正規化後のボーンを得る</param>
|
||||
/// <param name="dstLocalToWorldMatrix"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static (Mesh, Transform[]) NormalizeSkinnedMesh(
|
||||
public static Mesh NormalizeSkinnedMesh(
|
||||
SkinnedMeshRenderer src,
|
||||
Dictionary<Transform, Transform> boneMap,
|
||||
Matrix4x4 dstLocalToWorldMatrix,
|
||||
bool FreezeBlendShape = true)
|
||||
Dictionary<Transform, Transform> boneMap)
|
||||
{
|
||||
if (src == null
|
||||
|| !src.enabled
|
||||
@@ -180,16 +177,6 @@ namespace UniGLTF.MeshUtility
|
||||
src.sharedMesh = srcMesh;
|
||||
}
|
||||
|
||||
var blendShapeBackup = new List<float>();
|
||||
if (!FreezeBlendShape)
|
||||
{
|
||||
for (int i = 0; i < srcMesh.blendShapeCount; ++i)
|
||||
{
|
||||
blendShapeBackup.Add(src.GetBlendShapeWeight(i));
|
||||
src.SetBlendShapeWeight(i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// BakeMesh
|
||||
var mesh = srcMesh.Copy(false);
|
||||
mesh.name = srcMesh.name + ".baked";
|
||||
@@ -198,9 +185,6 @@ namespace UniGLTF.MeshUtility
|
||||
// 新しい骨格のボーンウェイトを作成する
|
||||
mesh.boneWeights = MapBoneWeight(srcMesh.boneWeights, boneMap, src.bones, dstBones);
|
||||
|
||||
// recalc bindposes
|
||||
mesh.bindposes = dstBones.Select(x => x.worldToLocalMatrix * dstLocalToWorldMatrix).ToArray();
|
||||
|
||||
//var m = src.localToWorldMatrix; // include scaling
|
||||
var m = default(Matrix4x4);
|
||||
m.SetTRS(Vector3.zero, src.transform.rotation, Vector3.one); // rotation only
|
||||
@@ -211,10 +195,19 @@ namespace UniGLTF.MeshUtility
|
||||
//
|
||||
CopyBlendShapes(src, srcMesh, mesh, m);
|
||||
|
||||
for (int i = 0; i < blendShapeBackup.Count; ++i)
|
||||
{
|
||||
src.SetBlendShapeWeight(i, blendShapeBackup[i]);
|
||||
}
|
||||
// var blendShapeBackup = new List<float>();
|
||||
// if (!FreezeBlendShape)
|
||||
// {
|
||||
// for (int i = 0; i < srcMesh.blendShapeCount; ++i)
|
||||
// {
|
||||
// blendShapeBackup.Add(src.GetBlendShapeWeight(i));
|
||||
// src.SetBlendShapeWeight(i, 0);
|
||||
// }
|
||||
// }
|
||||
// for (int i = 0; i < blendShapeBackup.Count; ++i)
|
||||
// {
|
||||
// src.SetBlendShapeWeight(i, blendShapeBackup[i]);
|
||||
// }
|
||||
|
||||
if (!hasBoneWeight)
|
||||
{
|
||||
@@ -223,7 +216,7 @@ namespace UniGLTF.MeshUtility
|
||||
src.sharedMesh = originalSrcMesh;
|
||||
}
|
||||
|
||||
return (mesh, dstBones);
|
||||
return mesh;
|
||||
}
|
||||
|
||||
private static void CopyBlendShapes(SkinnedMeshRenderer src, Mesh srcMesh, Mesh mesh, Matrix4x4 m)
|
||||
|
||||
Reference in New Issue
Block a user