Skip to content

Commit

Permalink
fix missing extras property deserialization in MeshPrimitive deserial…
Browse files Browse the repository at this point in the history
…izer

fixes prefrontalcortex#126 properly
  • Loading branch information
hybridherbst committed Jan 6, 2024
1 parent f949b45 commit 49b433f
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions Runtime/Plugins/GLTFSerialization/Schema/MeshPrimitive.cs
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using GLTF.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace GLTF.Schema
{
Expand Down Expand Up @@ -148,29 +150,18 @@ public static MeshPrimitive Deserialize(GLTFRoot root, JsonReader reader)
skipStartObjectRead: true);
});
break;
case "extras":
// GLTF does not support morph target names, serialize in extras for now
default:
primitive.DefaultPropertyDeserializer(root, reader);

// GLTF does not support morph target names, serialize/deserialize in extras
// https://github.com/KhronosGroup/glTF/issues/1036
if (reader.Read() && reader.TokenType == JsonToken.StartObject)
if (curProp == "extras" && primitive.Extras != null)
{
while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
if (primitive.Extras is JObject extras && extras.TryGetValue("targetNames", out var targetNames) && targetNames is JArray)
{
var extraProperty = reader.Value.ToString();
switch (extraProperty)
{
case "targetNames":
primitive.TargetNames = reader.ReadStringList();
break;
default:
primitive.DefaultPropertyDeserializer(root, reader);
break;
}
primitive.TargetNames = targetNames.Values<string>().ToList();
}
}

break;
default:
primitive.DefaultPropertyDeserializer(root, reader);
break;
}
}
Expand Down

0 comments on commit 49b433f

Please sign in to comment.