diff --git a/Assets/UniGLTF/Editor/Generator/Generator.cs b/Assets/UniGLTF/Editor/Generator/Generator.cs index 83e9f3499..d31b30925 100644 --- a/Assets/UniGLTF/Editor/Generator/Generator.cs +++ b/Assets/UniGLTF/Editor/Generator/Generator.cs @@ -1,13 +1,14 @@ using System; using System.IO; using System.Linq; +using System.Text; using UniGLTF.JsonSchema; namespace GenerateUniGLTFSerialization { public class Generator { - static void ClearFolder(DirectoryInfo dir) + static void DeleteAllInDirectory(DirectoryInfo dir) { Console.WriteLine($"clear: {dir}"); @@ -22,6 +23,23 @@ namespace GenerateUniGLTFSerialization } } + static void CleanDirectory(DirectoryInfo dir) + { + // clear or create folder + if (dir.Exists) + { + if (dir.EnumerateFileSystemInfos().Any()) + { + DeleteAllInDirectory(dir); + } + } + else + { + Console.WriteLine($"create: {dir}"); + dir.Create(); + } + } + static string CleanupTitle(string title) { if (string.IsNullOrEmpty(title)) @@ -43,29 +61,32 @@ namespace GenerateUniGLTFSerialization return filename.Split('.').First(); } - public static void GenerateTo(JsonSchemaSource root, DirectoryInfo dir, bool clearFolder) + static void WriteAllTextForce(string path, string contents) { - // clear or create folder - if (dir.Exists) + if (string.IsNullOrEmpty(path)) return; + + var dir = Path.GetDirectoryName(path); + if (string.IsNullOrEmpty(dir)) return; + + var dirInfo = new DirectoryInfo(dir); + if (!dirInfo.Exists) { - if (dir.EnumerateFileSystemInfos().Any()) - { - if (!clearFolder) - { - Console.WriteLine($"{dir} is not empty."); - return; - } - - // clear - ClearFolder(dir); - } - } - else - { - Console.WriteLine($"create: {dir}"); - dir.Create(); + dirInfo.Create(); } + if (File.Exists(path)) + { + File.Delete(path); + } + + File.WriteAllText(path, contents, Encoding.UTF8); + } + + public static void GenerateTo(JsonSchemaSource root, DirectoryInfo formatDir, DirectoryInfo serializerDir) + { + CleanDirectory(formatDir); + CleanDirectory(serializerDir); + foreach (var s in root.Traverse()) { // title を掃除 @@ -73,30 +94,30 @@ namespace GenerateUniGLTFSerialization } { - var dst = Path.Combine(dir.FullName, "Format.g.cs"); + var dst = Path.Combine(formatDir.FullName, "Format.g.cs"); Console.WriteLine(dst); using (var w = new StringWriter()) { FormatWriter.Write(w, root, GetStem(root.FilePath.Name)); - File.WriteAllText(dst, w.ToString().Replace("\r\n", "\n")); + WriteAllTextForce(dst, w.ToString().Replace("\r\n", "\n")); } } { - var dst = Path.Combine(dir.FullName, "Deserializer.g.cs"); + var dst = Path.Combine(serializerDir.FullName, "Deserializer.g.cs"); Console.WriteLine(dst); using (var w = new StringWriter()) { DeserializerWriter.Write(w, root, GetStem(root.FilePath.Name)); - File.WriteAllText(dst, w.ToString().Replace("\r\n", "\n")); + WriteAllTextForce(dst, w.ToString().Replace("\r\n", "\n")); } } { - var dst = Path.Combine(dir.FullName, "Serializer.g.cs"); + var dst = Path.Combine(serializerDir.FullName, "Serializer.g.cs"); Console.WriteLine(dst); using (var w = new StringWriter()) { SerializerWriter.Write(w, root, GetStem(root.FilePath.Name)); - File.WriteAllText(dst, w.ToString().Replace("\r\n", "\n")); + WriteAllTextForce(dst, w.ToString().Replace("\r\n", "\n")); } } } diff --git a/Assets/VRM10/Editor/GeneratorMenu.cs b/Assets/VRM10/Editor/GeneratorMenu.cs index c2e084fb0..55e36c0fc 100644 --- a/Assets/VRM10/Editor/GeneratorMenu.cs +++ b/Assets/VRM10/Editor/GeneratorMenu.cs @@ -39,26 +39,33 @@ namespace UniVRM10 { // VRMC_vrm "vrm-specification/specification/VRMC_vrm-1.0_draft/schema/VRMC_vrm.schema.json", - "Assets/VRM10/Runtime/Format/Vrm", // dst + "Assets/VRM10/Runtime/Format/Vrm", // format + "Assets/VRM10/Runtime/Format/Vrm", // serializer // VRMC_node_constraint "vrm-specification/specification/VRMC_node_constraint-1.0_draft/schema/VRMC_node_constraint.schema.json", - "Assets/VRM10/Runtime/Format/Constraints", // dst + "Assets/VRM10/Runtime/Format/Constraints", // format + "Assets/VRM10/Runtime/Format/Constraints", // serializer // VRMC_materials_mtoon "vrm-specification/specification/VRMC_materials_mtoon-1.0_draft/schema/VRMC_materials_mtoon.schema.json", - "Assets/VRM10/Runtime/Format/MaterialsMToon", // dst + "Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon", // format + "Assets/VRM10/Runtime/Format/MaterialsMToon", // serializer // VRMC_springBone "vrm-specification/specification/VRMC_springBone-1.0_draft/schema/VRMC_springBone.schema.json", - "Assets/VRM10/Runtime/Format/SpringBone", // dst + "Assets/VRM10/Runtime/Format/SpringBone", // format + "Assets/VRM10/Runtime/Format/SpringBone", // serializer }; - for (int i = 0; i < args.Length; i += 2) + for (int i = 0; i < args.Length; i += 3) { var extensionSchemaPath = new FileInfo(Path.Combine(projectRoot.FullName, args[i])); var parser = new UniGLTF.JsonSchema.JsonSchemaParser(gltf.Directory, extensionSchemaPath.Directory); var extensionSchema = parser.Load(extensionSchemaPath, ""); - var dst = new DirectoryInfo(Path.Combine(projectRoot.FullName, args[i + 1])); - Debug.Log(dst); + var formatDst = new DirectoryInfo(Path.Combine(projectRoot.FullName, args[i + 1])); + Debug.Log($"Format.g Dir: {formatDst}"); + + var serializerDst = new DirectoryInfo(Path.Combine(projectRoot.FullName, args[i + 2])); + Debug.Log($"Serializer/Deserializer.g Dir: {serializerDst}"); if (debug) { @@ -66,7 +73,7 @@ namespace UniVRM10 } else { - GenerateUniGLTFSerialization.Generator.GenerateTo(extensionSchema, dst, clearFolder: true); + GenerateUniGLTFSerialization.Generator.GenerateTo(extensionSchema, formatDst, serializerDst); } } } diff --git a/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs b/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs index 04fa4b622..313e90482 100644 --- a/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs +++ b/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using UniJSON; using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs b/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs index 0d3af20a9..f80be4f7e 100644 --- a/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs +++ b/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs b/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs index 02b319f02..717fcb990 100644 --- a/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs +++ b/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; using System.Linq; diff --git a/Assets/VRM10/Runtime/Format/MaterialsMToon/Deserializer.g.cs b/Assets/VRM10/Runtime/Format/MaterialsMToon/Deserializer.g.cs index 12cedff0c..49c5c34e4 100644 --- a/Assets/VRM10/Runtime/Format/MaterialsMToon/Deserializer.g.cs +++ b/Assets/VRM10/Runtime/Format/MaterialsMToon/Deserializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using UniJSON; using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/MaterialsMToon/Serializer.g.cs b/Assets/VRM10/Runtime/Format/MaterialsMToon/Serializer.g.cs index 397041fca..549c2b81d 100644 --- a/Assets/VRM10/Runtime/Format/MaterialsMToon/Serializer.g.cs +++ b/Assets/VRM10/Runtime/Format/MaterialsMToon/Serializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; using System.Linq; diff --git a/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs b/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs index 28fe96538..d2537dfbe 100644 --- a/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs +++ b/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using UniJSON; using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs b/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs index 122860d74..e9695e407 100644 --- a/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs +++ b/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs b/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs index ef63c1cd2..194b7c75d 100644 --- a/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs +++ b/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; using System.Linq; diff --git a/Assets/VRM10/Runtime/Format/Vrm/Deserializer.g.cs b/Assets/VRM10/Runtime/Format/Vrm/Deserializer.g.cs index 20a866f87..6fd912718 100644 --- a/Assets/VRM10/Runtime/Format/Vrm/Deserializer.g.cs +++ b/Assets/VRM10/Runtime/Format/Vrm/Deserializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using UniJSON; using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/Vrm/Format.g.cs b/Assets/VRM10/Runtime/Format/Vrm/Format.g.cs index 22167bc20..7b9be66fe 100644 --- a/Assets/VRM10/Runtime/Format/Vrm/Format.g.cs +++ b/Assets/VRM10/Runtime/Format/Vrm/Format.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/Vrm/Serializer.g.cs b/Assets/VRM10/Runtime/Format/Vrm/Serializer.g.cs index 610fec3c9..52b057516 100644 --- a/Assets/VRM10/Runtime/Format/Vrm/Serializer.g.cs +++ b/Assets/VRM10/Runtime/Format/Vrm/Serializer.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; using System.Linq; diff --git a/Assets/VRM10/Runtime/VRM10.asmdef b/Assets/VRM10/Runtime/VRM10.asmdef index e83e938f4..05f8e8642 100644 --- a/Assets/VRM10/Runtime/VRM10.asmdef +++ b/Assets/VRM10/Runtime/VRM10.asmdef @@ -3,10 +3,9 @@ "references": [ "VrmLib", "MToon", - "MeshUtility", - "MeshUtility.Editor", "UniGLTF", - "VRMShaders.GLTF.IO.Runtime" + "VRMShaders.GLTF.IO.Runtime", + "VRMShaders.VRM10.Format.Runtime" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/VRMShaders/VRM10/Format.meta b/Assets/VRMShaders/VRM10/Format.meta new file mode 100644 index 000000000..f42cb0b10 --- /dev/null +++ b/Assets/VRMShaders/VRM10/Format.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 83500e0cfc53cf04f95af8a60cc32017 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRMShaders/VRM10/Format/Runtime.meta b/Assets/VRMShaders/VRM10/Format/Runtime.meta new file mode 100644 index 000000000..9dda04a2d --- /dev/null +++ b/Assets/VRMShaders/VRM10/Format/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 07be59cdcf4b2df4ca9241939bf1054e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon.meta b/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon.meta new file mode 100644 index 000000000..7bf05b5d3 --- /dev/null +++ b/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c6bae94a423d90d45bc6f1bd1eada5fe +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Format/MaterialsMToon/Format.g.cs b/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon/Format.g.cs similarity index 97% rename from Assets/VRM10/Runtime/Format/MaterialsMToon/Format.g.cs rename to Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon/Format.g.cs index 91a660a4d..89133cd90 100644 --- a/Assets/VRM10/Runtime/Format/MaterialsMToon/Format.g.cs +++ b/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon/Format.g.cs @@ -1,4 +1,4 @@ -// This file is generated from JsonSchema. Don't modify this source code. +// This file is generated from JsonSchema. Don't modify this source code. using System; using System.Collections.Generic; diff --git a/Assets/VRM10/Runtime/Format/MaterialsMToon/Format.g.cs.meta b/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon/Format.g.cs.meta similarity index 83% rename from Assets/VRM10/Runtime/Format/MaterialsMToon/Format.g.cs.meta rename to Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon/Format.g.cs.meta index afa8ef7fa..d1f29bc99 100644 --- a/Assets/VRM10/Runtime/Format/MaterialsMToon/Format.g.cs.meta +++ b/Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon/Format.g.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 95a156592f2b7fc47b1b6cc557d1df4b +guid: 7bbff45dd057a5a4d935d5ee9a64e40a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRMShaders/VRM10/Format/Runtime/VRMShaders.VRM10.Format.Runtime.asmdef b/Assets/VRMShaders/VRM10/Format/Runtime/VRMShaders.VRM10.Format.Runtime.asmdef new file mode 100644 index 000000000..fd9a63aee --- /dev/null +++ b/Assets/VRMShaders/VRM10/Format/Runtime/VRMShaders.VRM10.Format.Runtime.asmdef @@ -0,0 +1,13 @@ +{ + "name": "VRMShaders.VRM10.Format.Runtime", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/Format/Runtime/VRMShaders.VRM10.Format.Runtime.asmdef.meta b/Assets/VRMShaders/VRM10/Format/Runtime/VRMShaders.VRM10.Format.Runtime.asmdef.meta new file mode 100644 index 000000000..3667d97ad --- /dev/null +++ b/Assets/VRMShaders/VRM10/Format/Runtime/VRMShaders.VRM10.Format.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bce005214fa49654d93927908c15b1f2 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: