Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate MToon format.g.cs in VRMShaders #927

Merged
merged 2 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions Assets/UniGLTF/Editor/Generator/Generator.cs
Original file line number Diff line number Diff line change
@@ -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}");

Expand All @@ -22,6 +23,23 @@ static void ClearFolder(DirectoryInfo dir)
}
}

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))
Expand All @@ -43,60 +61,63 @@ static string GetStem(string filename)
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);
}
dirInfo.Create();
}
else

if (File.Exists(path))
{
Console.WriteLine($"create: {dir}");
dir.Create();
File.Delete(path);
}


File.WriteAllText(path, contents, Encoding.UTF8);
}

public static void GenerateTo(JsonSchemaSource root, DirectoryInfo formatDir, DirectoryInfo serializerDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatDir と serializerDir が分かれた

{
CleanDirectory(formatDir);
CleanDirectory(serializerDir);

foreach (var s in root.Traverse())
{
// title を掃除
s.title = CleanupTitle(s.title);
}

{
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"));
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions Assets/VRM10/Editor/GeneratorMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,41 @@ static void Run(bool debug)
{
// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ

"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)
{
Debug.Log(extensionSchema.Dump());
}
else
{
GenerateUniGLTFSerialization.Generator.GenerateTo(extensionSchema, dst, clearFolder: true);
GenerateUniGLTFSerialization.Generator.GenerateTo(extensionSchema, formatDst, serializerDst);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/Constraints/Format.g.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/MaterialsMToon/Serializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/Vrm/Deserializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/Vrm/Format.g.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/Format/Vrm/Serializer.g.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 2 additions & 3 deletions Assets/VRM10/Runtime/VRM10.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
8 changes: 8 additions & 0 deletions Assets/VRMShaders/VRM10/Format.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/VRMShaders/VRM10/Format/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "VRMShaders.VRM10.Format.Runtime",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.