diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index 7ee835e14..071f61e98 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -38,7 +38,7 @@ namespace UniVRM10 m_parser = null; return; } - m_model = VrmLoader.CreateVrmModel(m_parser); + m_model = ModelReader.Read(m_parser); } enum Tabs diff --git a/Assets/VRM10/Runtime/IO/ComponentBuilder.cs b/Assets/VRM10/Runtime/IO/ComponentBuilder.cs deleted file mode 100644 index eace97c9e..000000000 --- a/Assets/VRM10/Runtime/IO/ComponentBuilder.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using UnityEngine; -using System.Linq; -using System.Collections.Generic; - -namespace UniVRM10 -{ - public static class ComponentBuilder - { - #region Util - static (Transform, Mesh) GetTransformAndMesh(Transform t) - { - var skinnedMeshRenderer = t.GetComponent(); - if (skinnedMeshRenderer != null) - { - return (t, skinnedMeshRenderer.sharedMesh); - } - - var filter = t.GetComponent(); - if (filter != null) - { - return (t, filter.sharedMesh); - } - - return default; - } - #endregion - } -} diff --git a/Assets/VRM10/Runtime/IO/MeshLoader.cs b/Assets/VRM10/Runtime/IO/MeshLoader.cs index d199dd2f8..5f5af64d2 100644 --- a/Assets/VRM10/Runtime/IO/MeshLoader.cs +++ b/Assets/VRM10/Runtime/IO/MeshLoader.cs @@ -1,12 +1,17 @@ using System; using UnityEngine; -using UnityEngine.Rendering; namespace UniVRM10 { public static class MeshLoader { - public static void LoadMesh(this Mesh mesh, VrmLib.Mesh src, VrmLib.Skin skin = null) + /// + /// VrmLib.Mesh => UnityEngine.Mesh + /// + /// + /// + /// + public static void LoadMesh(this UnityEngine.Mesh mesh, VrmLib.Mesh src, VrmLib.Skin skin = null) { mesh.vertices = src.VertexBuffer.Positions.GetSpan().ToArray(); mesh.normals = src.VertexBuffer.Normals?.GetSpan().ToArray(); diff --git a/Assets/VRM10/Runtime/IO/ModelLoader.cs b/Assets/VRM10/Runtime/IO/Model/ModelReader.cs similarity index 82% rename from Assets/VRM10/Runtime/IO/ModelLoader.cs rename to Assets/VRM10/Runtime/IO/Model/ModelReader.cs index 0c283ed05..876c3c855 100644 --- a/Assets/VRM10/Runtime/IO/ModelLoader.cs +++ b/Assets/VRM10/Runtime/IO/Model/ModelReader.cs @@ -1,12 +1,15 @@ -using System; +using System.IO; using System.Linq; using VrmLib; namespace UniVRM10 { - public static class ModelLoader + /// + /// GLTF => VrmLib.Model + /// + public static class ModelReader { - public static Model Load(Vrm10Storage storage, string rootName) + static Model Load(Vrm10Storage storage, string rootName) { if (storage == null) { @@ -70,5 +73,13 @@ namespace UniVRM10 return model; } + + public static Model Read(UniGLTF.GltfParser parser) + { + var storage = new Vrm10Storage(parser); + var model = Load(storage, Path.GetFileName(parser.TargetPath)); + model.ConvertCoordinate(Coordinates.Unity); + return model; + } } } diff --git a/Assets/VRM10/Runtime/IO/RuntimeVrmConverter.cs.meta b/Assets/VRM10/Runtime/IO/Model/ModelReader.cs.meta similarity index 83% rename from Assets/VRM10/Runtime/IO/RuntimeVrmConverter.cs.meta rename to Assets/VRM10/Runtime/IO/Model/ModelReader.cs.meta index a49ea9a83..f9a24df05 100644 --- a/Assets/VRM10/Runtime/IO/RuntimeVrmConverter.cs.meta +++ b/Assets/VRM10/Runtime/IO/Model/ModelReader.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6b619b24f8ac1494290458193ebca6aa +guid: fb219f8797f990649a7531dbb96d3305 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Runtime/IO/RuntimeVrmConverter.cs b/Assets/VRM10/Runtime/IO/Model/ModelWriter.cs similarity index 99% rename from Assets/VRM10/Runtime/IO/RuntimeVrmConverter.cs rename to Assets/VRM10/Runtime/IO/Model/ModelWriter.cs index afe1b3369..b8d28d7f1 100644 --- a/Assets/VRM10/Runtime/IO/RuntimeVrmConverter.cs +++ b/Assets/VRM10/Runtime/IO/Model/ModelWriter.cs @@ -16,7 +16,6 @@ namespace UniVRM10 public List Materials = new List(); public Dictionary Meshes = new Dictionary(); - #region Export 1.0 /// /// metaObject が null のときは、root から取得する /// @@ -123,9 +122,6 @@ namespace UniVRM10 return Model; } - #endregion - - private static void CreateNodes( Transform parentTransform, diff --git a/Assets/VRM10/Runtime/IO/ComponentBuilder.cs.meta b/Assets/VRM10/Runtime/IO/Model/ModelWriter.cs.meta similarity index 83% rename from Assets/VRM10/Runtime/IO/ComponentBuilder.cs.meta rename to Assets/VRM10/Runtime/IO/Model/ModelWriter.cs.meta index 95f8dff4e..f387fd775 100644 --- a/Assets/VRM10/Runtime/IO/ComponentBuilder.cs.meta +++ b/Assets/VRM10/Runtime/IO/Model/ModelWriter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a6cc4e6978a4fdf40999cc13aaa472fe +guid: fd51b1ef2f1840e438e6a91fe1389a75 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Runtime/IO/ModelLoader.cs.meta b/Assets/VRM10/Runtime/IO/ModelLoader.cs.meta deleted file mode 100644 index 9930454b6..000000000 --- a/Assets/VRM10/Runtime/IO/ModelLoader.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 42576b7471f4a4e4fb25c1815a92f44b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs b/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs index 0fc7406cf..159a94883 100644 --- a/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs +++ b/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using UniGLTF; @@ -24,7 +25,7 @@ namespace UniVRM10 : base(parser, externalObjectMap.Select(kv => (kv.Key.Name, kv.Value))) { m_externalMap = externalObjectMap; - m_model = VrmLoader.CreateVrmModel(parser); + m_model = ModelReader.Read(parser); // for `VRMC_materials_mtoon` this.GltfMaterialImporter.GltfMaterialParamProcessors.Insert(0, Vrm10MaterialImporter.TryCreateParam); diff --git a/Assets/VRM10/Runtime/IO/VrmLoader.cs b/Assets/VRM10/Runtime/IO/VrmLoader.cs deleted file mode 100644 index cc59d996d..000000000 --- a/Assets/VRM10/Runtime/IO/VrmLoader.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.IO; -using VrmLib; -using UniGLTF; - -namespace UniVRM10 -{ - /// - /// utility for load VrmLib Model from byte[] - /// - public static class VrmLoader - { - public static Model CreateVrmModel(GltfParser parser) - { - var storage = new Vrm10Storage(parser); - var model = ModelLoader.Load(storage, Path.GetFileName(parser.TargetPath)); - model.ConvertCoordinate(Coordinates.Unity); - return model; - } - } -} diff --git a/Assets/VRM10/Runtime/IO/VrmLoader.cs.meta b/Assets/VRM10/Runtime/IO/VrmLoader.cs.meta deleted file mode 100644 index af911b20b..000000000 --- a/Assets/VRM10/Runtime/IO/VrmLoader.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ef069ccddc286cc4e930ba33447b0094 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM10/Tests/ApiSampleTests.cs b/Assets/VRM10/Tests/ApiSampleTests.cs index fa72a5dd5..a79b552ce 100644 --- a/Assets/VRM10/Tests/ApiSampleTests.cs +++ b/Assets/VRM10/Tests/ApiSampleTests.cs @@ -1,9 +1,7 @@ -using System; -using System.IO; +using System.IO; using NUnit.Framework; using UniGLTF; using UnityEngine; -using UnityEngine.TestTools; using VRMShaders; namespace UniVRM10.Test @@ -17,7 +15,7 @@ namespace UniVRM10.Test var parser = new GltfParser(); parser.Parse("migrated", bytes); - var model = UniVRM10.VrmLoader.CreateVrmModel(parser); + var model = ModelReader.Read(parser); return model; }