mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 19:38:13 -05:00
Merge pull request #927 from Santarh/generateMtoonFormatInVRMShaders
Generate MToon format.g.cs in VRMShaders
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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": [],
|
||||
|
||||
8
Assets/VRMShaders/VRM10/Format.meta
Normal file
8
Assets/VRMShaders/VRM10/Format.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83500e0cfc53cf04f95af8a60cc32017
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/VRMShaders/VRM10/Format/Runtime.meta
Normal file
8
Assets/VRMShaders/VRM10/Format/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07be59cdcf4b2df4ca9241939bf1054e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6bae94a423d90d45bc6f1bd1eada5fe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95a156592f2b7fc47b1b6cc557d1df4b
|
||||
guid: 7bbff45dd057a5a4d935d5ee9a64e40a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "VRMShaders.VRM10.Format.Runtime",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bce005214fa49654d93927908c15b1f2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user