From adab2359904d32ed22e58a4347ed2fdb85b3e669 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 8 Mar 2024 16:04:04 +0900 Subject: [PATCH] impl FreezeMesh for glTF export --- .../Runtime/UniGLTF/IO/GltfExportSettings.cs | 6 ++++++ Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs index a82686460..41468f154 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs @@ -53,5 +53,11 @@ namespace UniGLTF /// Export TEXCOORD_1 /// public bool ExportUvSecondary; + + /// + /// FreezeBlendShape + /// + [Tooltip("freeze rotation and scale and blendshape")] + public bool FreezeMesh = false; } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs index 8fcc316a4..bba0b974b 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using UniGLTF.MeshUtility; using UnityEngine; using VRMShaders; @@ -231,6 +232,18 @@ namespace UniGLTF public virtual void Export(ITextureSerializer textureSerializer) { + if (m_settings.FreezeMesh) + { + // Transform の回転とスケールを Mesh に適用します。 + // - BlendShape は現状がbakeされます + // - 回転とスケールが反映された新しい Mesh が作成されます + // - Transform の回転とスケールはクリアされます。world position を維持します + var newMeshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(Copy); + + // SkinnedMeshRenderer.sharedMesh と MeshFilter.sharedMesh を新しいMeshで置き換える + BoneNormalizer.Replace(Copy, newMeshMap, true, true); + } + Nodes = Copy.transform.Traverse() .Skip(1) // exclude root object for the symmetry with the importer .ToList();