From 99d1b5df63c4a7b0c67fa42aeb4f8eccb09e67ce Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 15 Dec 2021 17:31:04 +0900 Subject: [PATCH] implement importer normalize --- .../ScriptedImporter/VrmScriptedImporterImpl.cs | 8 +++++--- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs index 396a270be..45a0eb247 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs @@ -36,8 +36,8 @@ namespace UniVRM10 /// /// vrm0 だった場合に vrm1 化する /// - /// normalize する - public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, RenderPipelineTypes renderPipeline, bool normalize) + /// normalize する + public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, RenderPipelineTypes renderPipeline, bool doNormalize) { #if VRM_DEVELOP Debug.Log("OnImportAsset to " + scriptedImporter.assetPath); @@ -58,7 +58,9 @@ namespace UniVRM10 var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline); - using (var loader = new Vrm10Importer(result, extractedObjects, materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(result, extractedObjects, + materialGenerator: materialGenerator, + doNormalize: doNormalize)) { // settings TextureImporters foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable()) diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 6ebdf76c0..1ed82b9b1 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -20,11 +20,14 @@ namespace UniVRM10 IReadOnlyDictionary m_externalMap; + readonly bool m_doNormalize; + public Vrm10Importer( Vrm10Data vrm, IReadOnlyDictionary externalObjectMap = null, ITextureDeserializer textureDeserializer = null, - IMaterialDescriptorGenerator materialGenerator = null) + IMaterialDescriptorGenerator materialGenerator = null, + bool doNormalize = false) : base(vrm.Data, externalObjectMap, textureDeserializer) { if (vrm == null) @@ -32,6 +35,7 @@ namespace UniVRM10 throw new ArgumentNullException("vrm"); } m_vrm = vrm; + m_doNormalize = doNormalize; TextureDescriptorGenerator = new Vrm10TextureDescriptorGenerator(Data); MaterialDescriptorGenerator = materialGenerator ?? new Vrm10MaterialDescriptorGenerator(); @@ -74,6 +78,12 @@ namespace UniVRM10 // bin に対して右手左手変換を破壊的に実行することに注意 !(bin が変換済みになる) m_model = ModelReader.Read(Data); + if (m_doNormalize) + { + var result = VrmLib.ModelModifierExtensions.SkinningBake(new VrmLib.ModelModifier(m_model)); + Debug.Log($"SkinningBake: {result}"); + } + // assign humanoid bones if (m_vrm.VrmExtension.Humanoid is UniGLTF.Extensions.VRMC_vrm.Humanoid humanoid) { @@ -251,7 +261,7 @@ namespace UniVRM10 } // constraint await LoadConstraintAsync(awaitCaller, controller); - + // Hierarchyの構築が終わるまで遅延させる controller.enabled = true; } @@ -361,7 +371,7 @@ namespace UniVRM10 meta.Name = src.Name; meta.Version = src.Version; meta.ContactInformation = src.ContactInformation; - meta.ThirdPartyLicenses = src.ThirdPartyLicenses; + meta.ThirdPartyLicenses = src.ThirdPartyLicenses; // avatar meta.AvatarPermission = src.AvatarPermission; meta.ViolentUsage = src.AllowExcessivelyViolentUsage.GetValueOrDefault();