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

Experimental Exporterでjsonに空の配列が含まれglTF違反になってしまうことがあるのを修正 #486

Merged
merged 2 commits into from
Jul 27, 2020
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
23 changes: 22 additions & 1 deletion Assets/VRM/UniGLTF/Editor/Serialization/SerializerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ class Generator : IDisposable
{
{"gltf/animations", "if(value.animations!=null && value.animations.Count>0)" },
{"gltf/cameras", "if(value.cameras!=null && value.cameras.Count>0)" },
{"gltf/buffers", "if(value.buffers!=null && value.buffers.Count>0)" },
Copy link
Contributor Author

@saturday06 saturday06 Jul 26, 2020

Choose a reason for hiding this comment

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

{"gltf/bufferViews", "if(value.bufferViews!=null && value.bufferViews.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/bufferViews[]/byteStride", "if(false)" },
{"gltf/bufferViews[]/target", "if(value.target!=0)" },
{"gltf/animations[]/channels", "if(value.channels!=null && value.channels.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/animations[]/channels[]/target", "if(value!=null)" },
{"gltf/animations[]/samplers", "if(value.samplers!=null && value.samplers.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/accessors", "if(value.accessors!=null && value.accessors.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/accessors[]/max", "if(value.max!=null && value.max.Length>0)"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/accessors[]/min", "if(value.min!=null && value.min.Length>0)"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/accessors[]/sparse", "if(value.sparse!=null && value.sparse.count>0)"},
{"gltf/images", "if(value.images!=null && value.images.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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


{"gltf/meshes", "if(value.meshes!=null && value.meshes.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/meshes[]/primitives", "if(value.primitives!=null && value.primitives.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/meshes[]/primitives[]/targets", "if(value.targets!=null && value.targets.Count>0)" },

{"gltf/meshes[]/primitives[]/targets[]/POSITION", "if(value.POSITION!=-1)" },
Expand All @@ -67,17 +78,27 @@ class Generator : IDisposable
{"gltf/meshes[]/primitives[]/attributes/WEIGHTS_0", "if(value.WEIGHTS_0!=-1)"},

{"gltf/meshes[]/primitives[]/extras", "if(value.extras!=null && value.extras.targetNames!=null && value.extras.targetNames.Count>0)"},
{"gltf/meshes[]/weights", "if(value.weights!=null && value.weights.Length>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/materials", "if(value.materials!=null && value.materials.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/materials[]/alphaCutoff", "if(!string.IsNullOrEmpty(value.alphaMode))" },
{"gltf/nodes", "if(value.nodes!=null && value.nodes.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/nodes[]/camera", "if(value.camera!=-1)"},
{"gltf/nodes[]/mesh", "if(value.mesh!=-1)"},
{"gltf/nodes[]/skin", "if(value.skin!=-1)"},
{"gltf/nodes[]/children", "if(value.children != null && value.children.Length>0)"},
{"gltf/samplers", "if(value.samplers!=null && value.samplers.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/scenes", "if(value.scenes!=null && value.scenes.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/scenes[]/nodes", "if(value.nodes!=null && value.nodes.Length>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/skins", "if(value.skins!=null && value.skins.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/skins[]/skeleton", "if(value.skeleton!=-1)"},
{"gltf/extensionsRequired", "if(false)"},
{"gltf/skins[]/joints", "if(value.joints!=null && value.joints.Length>0)"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/extensionsUsed", "if(value.extensionsUsed!=null && value.extensionsUsed.Count>0)"}, // dummy
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{"gltf/extensionsRequired", "if(false && value.extensionsRequired!=null && value.extensionsRequired.Count>0)"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

こちらです。https://github.com/KhronosGroup/glTF/blob/dae8fe778b01aaffdde9d69a6116e30af11e3a1d/specification/2.0/schema/glTF.schema.json#L17-L25

すでにfalse固定になっていますが、いちおう防御的に記述しておきます。

{"gltf/extensions/VRM/humanoid/humanBones[]/axisLength", "if(value.axisLength>0)"},
{"gltf/extensions/VRM/humanoid/humanBones[]/center", "if(value.center!=Vector3.zero)"},
{"gltf/extensions/VRM/humanoid/humanBones[]/max", "if(value.max!=Vector3.zero)"},
{"gltf/extensions/VRM/humanoid/humanBones[]/min", "if(value.min!=Vector3.zero)"},
{"gltf/textures", "if(value.textures!=null && value.textures.Count>0)" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

};

public Generator(string path)
Expand Down
126 changes: 105 additions & 21 deletions Assets/VRM/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,52 @@ public static void GenSerialize(this IFormatter f, glTF value)
f.Key("asset"); f.GenSerialize(value.asset);
}

if(value.buffers!=null)
if(value.buffers!=null && value.buffers.Count>0)
{
f.Key("buffers"); f.GenSerialize(value.buffers);
}

if(value.bufferViews!=null)
if(value.bufferViews!=null && value.bufferViews.Count>0)
{
f.Key("bufferViews"); f.GenSerialize(value.bufferViews);
}

if(value.accessors!=null)
if(value.accessors!=null && value.accessors.Count>0)
{
f.Key("accessors"); f.GenSerialize(value.accessors);
}

if(value.textures!=null)
if(value.textures!=null && value.textures.Count>0)
{
f.Key("textures"); f.GenSerialize(value.textures);
}

if(value.samplers!=null)
if(value.samplers!=null && value.samplers.Count>0)
{
f.Key("samplers"); f.GenSerialize(value.samplers);
}

if(value.images!=null)
if(value.images!=null && value.images.Count>0)
{
f.Key("images"); f.GenSerialize(value.images);
}

if(value.materials!=null)
if(value.materials!=null && value.materials.Count>0)
{
f.Key("materials"); f.GenSerialize(value.materials);
}

if(value.meshes!=null)
if(value.meshes!=null && value.meshes.Count>0)
{
f.Key("meshes"); f.GenSerialize(value.meshes);
}

if(value.nodes!=null)
if(value.nodes!=null && value.nodes.Count>0)
{
f.Key("nodes"); f.GenSerialize(value.nodes);
}

if(value.skins!=null)
if(value.skins!=null && value.skins.Count>0)
{
f.Key("skins"); f.GenSerialize(value.skins);
}
Expand All @@ -76,7 +76,7 @@ public static void GenSerialize(this IFormatter f, glTF value)
f.Key("scene"); f.GenSerialize(value.scene);
}

if(value.scenes!=null)
if(value.scenes!=null && value.scenes.Count>0)
{
f.Key("scenes"); f.GenSerialize(value.scenes);
}
Expand All @@ -91,12 +91,12 @@ public static void GenSerialize(this IFormatter f, glTF value)
f.Key("cameras"); f.GenSerialize(value.cameras);
}

if(value.extensionsUsed!=null)
if(value.extensionsUsed!=null && value.extensionsUsed.Count>0)
{
f.Key("extensionsUsed"); f.GenSerialize(value.extensionsUsed);
}

if(false)
if(false && value.extensionsRequired!=null && value.extensionsRequired.Count>0)
{
f.Key("extensionsRequired"); f.GenSerialize(value.extensionsRequired);
}
Expand Down Expand Up @@ -276,12 +276,12 @@ public static void GenSerialize(this IFormatter f, glTFAccessor value)
f.Key("count"); f.GenSerialize(value.count);
}

if(value.max!=null)
if(value.max!=null && value.max.Length>0)
{
f.Key("max"); f.GenSerialize(value.max);
}

if(value.min!=null)
if(value.min!=null && value.min.Length>0)
{
f.Key("min"); f.GenSerialize(value.min);
}
Expand Down Expand Up @@ -634,6 +634,52 @@ public static void GenSerialize(this IFormatter f, glTFMaterialBaseColorTextureI
}


{
f.Key("texCoord"); f.GenSerialize(value.texCoord);
}

if(value.extensions!=null)
{
f.Key("extensions"); f.GenSerialize(value.extensions);
}

f.EndMap();
}

/// gltf/materials[]/pbrMetallicRoughness/baseColorTexture/extensions
public static void GenSerialize(this IFormatter f, glTFTextureInfo_extensions value)
{
f.BeginMap(0); // dummy

if(value.KHR_texture_transform!=null)
{
f.Key("KHR_texture_transform"); f.GenSerialize(value.KHR_texture_transform);
}

f.EndMap();
}

/// gltf/materials[]/pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform
public static void GenSerialize(this IFormatter f, glTF_KHR_texture_transform value)
{
f.BeginMap(0); // dummy

if(value.offset!=null)
{
f.Key("offset"); f.GenSerialize(value.offset);
}


{
f.Key("rotation"); f.GenSerialize(value.rotation);
}

if(value.scale!=null)
{
f.Key("scale"); f.GenSerialize(value.scale);
}


{
f.Key("texCoord"); f.GenSerialize(value.texCoord);
}
Expand All @@ -656,6 +702,11 @@ public static void GenSerialize(this IFormatter f, glTFMaterialMetallicRoughness
f.Key("texCoord"); f.GenSerialize(value.texCoord);
}

if(value.extensions!=null)
{
f.Key("extensions"); f.GenSerialize(value.extensions);
}

f.EndMap();
}

Expand All @@ -679,6 +730,11 @@ public static void GenSerialize(this IFormatter f, glTFMaterialNormalTextureInfo
f.Key("texCoord"); f.GenSerialize(value.texCoord);
}

if(value.extensions!=null)
{
f.Key("extensions"); f.GenSerialize(value.extensions);
}

f.EndMap();
}

Expand All @@ -702,6 +758,11 @@ public static void GenSerialize(this IFormatter f, glTFMaterialOcclusionTextureI
f.Key("texCoord"); f.GenSerialize(value.texCoord);
}

if(value.extensions!=null)
{
f.Key("extensions"); f.GenSerialize(value.extensions);
}

f.EndMap();
}

Expand All @@ -720,6 +781,11 @@ public static void GenSerialize(this IFormatter f, glTFMaterialEmissiveTextureIn
f.Key("texCoord"); f.GenSerialize(value.texCoord);
}

if(value.extensions!=null)
{
f.Key("extensions"); f.GenSerialize(value.extensions);
}

f.EndMap();
}

Expand Down Expand Up @@ -765,16 +831,21 @@ public static void GenSerialize(this IFormatter f, glTFMesh value)
f.Key("name"); f.GenSerialize(value.name);
}

if(value.primitives!=null)
if(value.primitives!=null && value.primitives.Count>0)
{
f.Key("primitives"); f.GenSerialize(value.primitives);
}

if(value.weights!=null)
if(value.weights!=null && value.weights.Length>0)
{
f.Key("weights"); f.GenSerialize(value.weights);
}

if(value.extras!=null)
{
f.Key("extras"); f.GenSerialize(value.extras);
}

f.EndMap();
}

Expand Down Expand Up @@ -936,6 +1007,19 @@ public static void GenSerialize(this IFormatter f, glTFPrimitives_extensions val
f.EndMap();
}

/// gltf/meshes[]/extras
public static void GenSerialize(this IFormatter f, glTFMesh_extras value)
{
f.BeginMap(0); // dummy

if(value.targetNames!=null)
{
f.Key("targetNames"); f.GenSerialize(value.targetNames);
}

f.EndMap();
}

/// gltf/nodes
public static void GenSerialize(this IFormatter f, List<glTFNode> value)
{
Expand Down Expand Up @@ -1053,7 +1137,7 @@ public static void GenSerialize(this IFormatter f, glTFSkin value)
f.Key("inverseBindMatrices"); f.GenSerialize(value.inverseBindMatrices);
}

if(value.joints!=null)
if(value.joints!=null && value.joints.Length>0)
{
f.Key("joints"); f.GenSerialize(value.joints);
}
Expand Down Expand Up @@ -1087,7 +1171,7 @@ public static void GenSerialize(this IFormatter f, gltfScene value)
{
f.BeginMap(0); // dummy

if(value.nodes!=null)
if(value.nodes!=null && value.nodes.Length>0)
{
f.Key("nodes"); f.GenSerialize(value.nodes);
}
Expand Down Expand Up @@ -1121,12 +1205,12 @@ public static void GenSerialize(this IFormatter f, glTFAnimation value)
f.Key("name"); f.GenSerialize(value.name);
}

if(value.channels!=null)
if(value.channels!=null && value.channels.Count>0)
{
f.Key("channels"); f.GenSerialize(value.channels);
}

if(value.samplers!=null)
if(value.samplers!=null && value.samplers.Count>0)
{
f.Key("samplers"); f.GenSerialize(value.samplers);
}
Expand Down